Commit 1d792b90 authored by mikeytown2's avatar mikeytown2

Issue #1543908 by mikeytown2: make pass by reference work in php 5.3

parent 02c1649b
......@@ -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.
<?php
// Code from system_rebuild_module_data().
$modules = _system_rebuild_module_data();
ksort($modules);
// Show first module before running system_get_files_database().
echo httprl_pr(current($modules));
$callback_options = array(
array(
'function' => '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));
?>
......@@ -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();
......
......@@ -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(' ', '&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(implode("\n", $output)));
// Replace whitespace with html markup.
$output = str_replace(' ', '&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(implode("\n", $output))) . '<br />';
return $output;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment