diff --git a/README.txt b/README.txt index 061eee0..e71c56f 100644 --- a/README.txt +++ b/README.txt @@ -284,3 +284,31 @@ in the callback options. httprl_send_request(); ?> + +Pass by reference example. Example is D7 only; pass by reference works in +D6 & D7. + + 'system_get_files_database', + 'return' => '', + ), + &$modules, 'module' + ); + httprl_queue_background_callback($callback_options); + + // Execute requests. + httprl_send_request(); + + // Show first module after running system_get_files_database(). + echo httprl_pr(current($modules)); + ?> + diff --git a/httprl.async.inc b/httprl.async.inc index bcf3493..423a6a7 100644 --- a/httprl.async.inc +++ b/httprl.async.inc @@ -23,14 +23,14 @@ function httprl_async_page() { } // Exit if the temp_key does not match a lock that has been taken. - // Wait up to 5 seconds for the lock to propagate out. + // Wait up to 2.5 seconds for the lock to propagate out. $tries = 0; while (lock_may_be_available($_POST['temp_key'])) { $tries++; if ($tries > 5) { httprl_fast403(); } - sleep(1); + usleep(500000); // Sleep for 500 miliseconds; } // If request was a non blocking one, cut the connection right here. @@ -47,7 +47,13 @@ function httprl_async_page() { } // Unpack arguments. - $args = unserialize($_POST['args']); + $input_args = unserialize($_POST['args']); + + // Pass by reference trick for call_user_func_array(). + $args = array(); + foreach ($input_args as &$arg) { + $args[] = &$arg; + } // Caputure anything printed out. ob_start(); diff --git a/httprl.module b/httprl.module index b962eff..6b7fd2d 100644 --- a/httprl.module +++ b/httprl.module @@ -1261,6 +1261,7 @@ function httprl_decode_data(&$result) { } $result->data = $output; } + // Decompress if compressed. elseif (isset($result->headers['content-encoding'])) { if ($result->headers['content-encoding'] == 'gzip') { $result->data = gzinflate(substr($result->data, 10)); @@ -1477,17 +1478,24 @@ function httprl_lock_release($name) { * Human readable HTML version of the data. */ function httprl_pr($data) { + // Get extra arguments passed in. $data = func_get_args(); if (count($data) == 1) { $data = array_pop($data); } + + // Remove non UTF-8 Characters, escape HTML markup, remove extra new lines. $output = array_filter(explode("\n", htmlentities(iconv('utf-8', 'utf-8//IGNORE', print_r($data, TRUE)), ENT_QUOTES, 'UTF-8'))); + + // Whitespace compression. foreach ($output as $key => $value) { if (str_replace(' ', '', $value) == "(") { $output[$key-1] .= ' ('; unset($output[$key]); } } - $output = str_replace(' ', '    ', nl2br(implode("\n", $output))); + + // Replace whitespace with html markup. + $output = str_replace(' ', '    ', nl2br(implode("\n", $output))) . '
'; return $output; }