Connecting Tech Pros Worldwide Help | Site Map

how to set Read timeout ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 21st, 2005, 11:05 PM
Lisa Pearlson
Guest
 
Posts: n/a
Default how to set Read timeout ?

Hi,

I am wanting to write an internet 'server' program. For ease, I want to use
PHP-CLI with XINET super server.
XINET communicates with the 'server' program via STDIN/STDOUT.

I'm not sure how to communicate with the client this way though.. I can open
stdin/out as a file, and use read and write operations, as if it were a
regular file.. however, how can I set read timeouts on file read operations?

Basically what I want is:

- send binary data to the client
- read binary data from client, but with a timeout of 1 second.

So I want a 'blocking' read operation, but one that doesn't block forever,
but times out.
I know how many bytes I expect when doing a read operation, so perferably I
tell the read operation how many bytes to read.. if it is not received
within x seconds, it should time out.

How can this be done in PHP?

I think I have seen examples where somehow the STDIN/OUT is communicated
with by using socket read/write operations, but I have no clue how this is
done.. the advantage would be that the socket timeout functions could be
used.

Lisa



  #2  
Old November 21st, 2005, 11:05 PM
Janwillem Borleffs
Guest
 
Posts: n/a
Default Re: how to set Read timeout ?

Lisa Pearlson wrote:[color=blue]
> So I want a 'blocking' read operation, but one that doesn't block
> forever, but times out.
> I know how many bytes I expect when doing a read operation, so
> perferably I tell the read operation how many bytes to read.. if it
> is not received within x seconds, it should time out.
>
> How can this be done in PHP?
>[/color]

With PHP v > 4.3, you should be able to use stream_set_timeout for this:

http://www.php.net/stream_set_timeout


JW



  #3  
Old November 21st, 2005, 11:10 PM
HANS VERSTRAELEN
Guest
 
Posts: n/a
Default Re: how to set Read timeout ?

Hi Lisa,

e.g.

set_time_limit(5); // 5seconds timeout for php

$start_time = time();
$valid_read = read_data("$filename"); /* return 0 on error, 1 if
succesful */
$end_time2 = time() - $start_time;
echo "total executution time = ".$end_time2;

Good luck !

Hans

"Lisa Pearlson" <no@spam.plz> wrote in message
news:4377b481$0$20646$e4fe514c@dreader14.news.xs4a ll.nl...[color=blue]
> Hi,
>
> I am wanting to write an internet 'server' program. For ease, I want to[/color]
use[color=blue]
> PHP-CLI with XINET super server.
> XINET communicates with the 'server' program via STDIN/STDOUT.
>
> I'm not sure how to communicate with the client this way though.. I can[/color]
open[color=blue]
> stdin/out as a file, and use read and write operations, as if it were a
> regular file.. however, how can I set read timeouts on file read[/color]
operations?[color=blue]
>
> Basically what I want is:
>
> - send binary data to the client
> - read binary data from client, but with a timeout of 1 second.
>
> So I want a 'blocking' read operation, but one that doesn't block forever,
> but times out.
> I know how many bytes I expect when doing a read operation, so perferably[/color]
I[color=blue]
> tell the read operation how many bytes to read.. if it is not received
> within x seconds, it should time out.
>
> How can this be done in PHP?
>
> I think I have seen examples where somehow the STDIN/OUT is communicated
> with by using socket read/write operations, but I have no clue how this is
> done.. the advantage would be that the socket timeout functions could be
> used.
>
> Lisa
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.