470,874 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

is stream_set_timeout cumalitive?

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.

Jan 11 '06 #1
3 2154

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.

Jan 11 '06 #2
The answer is no.

Jan 11 '06 #3

Chung Leong wrote:
The answer is no.


No, it'd take 1 second, or no, it'd take 5?

Jan 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by yawnmoth | last post: by
2 posts views Thread by ggg | last post: by
4 posts views Thread by Tim Marshall | last post: by
13 posts views Thread by Adam | last post: by
2 posts views Thread by Lisa Pearlson | last post: by
reply views Thread by Peter Duniho | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.