|
Posted by yawnmoth on 01/11/06 08:03
yawnmoth wrote:
> Say I set the stream timeout to 5 seconds with stream_set_timeout, call
> fwrites, which takes 2 seconds, and then call fgets, which takes
> another 2 seconds. Would a subsequent call to fwrite timeout in 1
> second or in 5?
>
> I'd test it out myself, if I knew how to make stuff take 2 seconds to
> load, but alas - I don't.
Well... I wrote two scripts that I thought would test this, but
unfortunately, the only thing they seem to prove is that I don't have a
clue as to what I'm doing.
Here's the script we're trying to read - test.php:
<?
sleep(2);
echo "testing\r\n";
flush();
sleep(2);
echo "more testing\r\n";
flush();
sleep(2);
echo "even more testing\r\n";
?>
Here's the script that's doing the reading - read.php:
<?
$path = 'http://www.domain.tld/test.php';
$hostname = preg_replace('#http://([^/]*)/.*#','$1',$path);
$short_path = preg_replace('#http://[^/]*(/.*)#','$1',$path);
$start = time();
$fsock = fsockopen("tcp://$hostname", 80, $errno, $errstr, 1) or
exit("Failed: $errno - $errstr");
socket_set_timeout($fsock,5);
fputs($fsock,"GET $short_path HTTP/1.1\r\nHost:
$hostname\r\nConnection: close\r\n\r\n"); // works
echo fgets($fsock,1024);
echo "<br />fgets #1 ran at ".(time()-$start)." seconds<br />";
echo fgets($fsock,1024);
echo "<br />fgets #2 ran at ".(time()-$start)." seconds<br />";
echo fgets($fsock,1024);
echo "<br />fgets #3 ran at ".(time()-$start)." seconds<br />";
exit;
?>
When test.php is loaded in Firefox, it takes about six seconds. The
first two seconds witeness the output of "testing", the next two
seconds yield "more testing", etc.
When test.php is loaded with read.php, however, it seems to take just
two seconds. The output is this:
HTTP/1.1 200 OK
fgets #1 ran at 2 seconds
....
fgets #2 ran at 2 seconds
....
fgets #3 ran at 2 seconds
What I'd expect is something more like...
HTTP/1.1 200 OK
fgets #1 ran at 2 seconds
....
fgets #2 ran at 4 seconds
....
fgets #3 ran at ? seconds
Unfortunately, this isn't happening. Any ideas as to why would be
appreciated.
Navigation:
[Reply to this message]
|