[Sussex] Sockets - PHP, Fedora Core 3

Brendan Whelan b_whelan at mistral.co.uk
Wed Nov 9 20:39:48 UTC 2005


Hello,

I am attempting to "perfect" a socket driver which will received lines of text from another system.
The heart of the code, without the initial sockets opening instructions and debug messages is shown below.
Messages are received from the other system but the timeout isn't working properly. 
The results I get when no data is being transmitted from the other end is:

1. The read is completed several times but the buffer is empty and the time from before to after the read is zero i.e. it completes the read instantly.

2. I then get a couple of reads which wait for 10 seconds each returning an empty string. (This is almost what I want)

3. Return to step 1.

I would expect the read to timeout after 30 seconds, return an empty buffer and then wait for another 30 seconds.

Any suggestions much appreciated.

Brendan Whelan
----------------------------------------------------------------------------------
while ($continue == "Y")
{
    if ($conn != "")
    {
      $result = socket_close($conn);
    }

    $conn = socket_accept($sock);

    support_f_socket_timeout($conn);

    $received = socket_read($conn, 4096);
}
--------------------------------------------------------------------------------------
  function support_f_socket_timeout($conn)
   {
// Set the logic to wait for the read to complete or the timer to expire
     if (! $return = @socket_set_block($conn))
     {
       $last_error = socket_last_error();
       support_f_socket_report_error($receive_or_send, $debug, $last_error, 
          "Unable to set non block");
     }

// Set a time delay - NOTE: Hard coded in the call
     if (! $return = socket_set_option($conn, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>30,"usec"=>0)))
     {
       $last_error = socket_last_error();
       support_f_socket_report_error($receive_or_send, $debug, $last_error, 
        "Unable to set timeout option");
     }
   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/sussex/attachments/20051109/bcad091a/attachment.htm 


More information about the Sussex mailing list