is stream_set_timeout cumalitive?

This is a discussion on is stream_set_timeout cumalitive? within the PHP Language forums, part of the PHP Programming Forums category; Say I set the stream timeout to 5 seconds with stream_set_timeout, call fwrites, which takes 2 seconds, and then call ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-11-2006
yawnmoth
 
Posts: n/a
Default 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.

Reply With Quote
  #2 (permalink)  
Old 01-11-2006
yawnmoth
 
Posts: n/a
Default Re: is stream_set_timeout cumalitive?


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.

Reply With Quote
  #3 (permalink)  
Old 01-11-2006
Chung Leong
 
Posts: n/a
Default Re: is stream_set_timeout cumalitive?

The answer is no.

Reply With Quote
  #4 (permalink)  
Old 01-11-2006
TerraFrost
 
Posts: n/a
Default Re: is stream_set_timeout cumalitive?


Chung Leong wrote:
> The answer is no.


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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:12 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0