Commit 0d5bb2b5 authored by mikeytown2's avatar mikeytown2

Issue #1697244 by mikeytown2: Move the TCP connection creation to inside of the event loop.

parent 7cd17368
......@@ -142,6 +142,8 @@ processing in the background.
<?php
httprl_background_processing('My Text');
// Everything after this point does not affect page load time.
sleep(5);
echo 'You should not see this text';
?>
......@@ -367,7 +369,7 @@ Get 2 results from 2 different queries at the hook_boot bootstrap level in D6.
// Second Query.
array(
'type' => 'function',
'call' => 'db_query',
'call' => 'db_query_range',
'args' => array('SELECT filename FROM {system} ORDER BY filename DESC', 0, 1),
),
array(
......@@ -536,8 +538,9 @@ non blocking background request.
Hit 4 different URLs, Using at least 2 that has a status code of 200 and
erroring out on the others that didn't return. Data is truncated as well.
erroring out the others that didn't return fast. Data is truncated as well.
<?php
// Array of URLs to get.
$urls = array(
'http://google.com/',
......@@ -561,12 +564,12 @@ erroring out on the others that didn't return. Data is truncated as well.
// Print what was done.
echo httprl_pr($requests);
function need_two_good_results($id, &$responses, &$streams, $current_time) {
function need_two_good_results($id, &$responses) {
static $counter = 0;
foreach ($responses as $id => &$result) {
// Skip if we got a 200.
if ($result->code == 200) {
$counter = $counter + 1;
$counter += 1;
continue;
}
if ($result->status == 'Done.') {
......@@ -576,12 +579,14 @@ erroring out on the others that didn't return. Data is truncated as well.
if ($counter >= 2) {
// Set the code to request was aborted.
$result->code = HTTPRL_REQUEST_ABORTED;
$result->error = 'Software caused connection abort.';
// Set status to done and set timeout.
$result->status = 'Done.';
$result->options['timeout'] = $result->options['timeout'] - $current_time;
$result->options['timeout'] -= $result->running_time;
// Close the file pointer and remove from the stream from the array.
fclose($streams[$id]);
unset($streams[$id]);
fclose($result->fp);
unset($result->fp);
}
}
}
......@@ -590,5 +595,5 @@ erroring out on the others that didn't return. Data is truncated as well.
// Only use the first and last 256 characters in the data array.
$result->data = substr($result->data, 0, 256) . "\n\n ... \n\n" . substr($result->data, strlen($result->data)-256);
}
?>
This diff is collapsed.
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