<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2745.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I have a sockets routine, in PHP, for sending 
messages to another system. It sends and receives responses but I am trying to 
make the program more robust by timing out the read from the other system. If I 
get a timeout I will assume that the message hasn't been receive and send it 
again. I have tried various methods without success.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>My original code connects as follows (I have 
stripped out all the error checking code, etc):</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>$sock = socket_create(AF_INET, SOCK_STREAM, 
0);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>$return = socket_bind($sock, $system_ip, 
$port);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>$client = socket_listen($sock);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>$conn = @socket_accept($sock)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>stream_set_timeout($conn, $timeout);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><FONT face=Arial size=2>
<DIV>Warning: stream_set_timeout(): supplied argument is not a valid stream 
resource</DIV>
<DIV>I close the program before exiting the program</DIV>
<DIV>------------------------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>I then tried to get a valid stream by using fsockopen:</DIV>
<DIV>&nbsp;</DIV>
<DIV>$sock = fsockopen($system_ip, $port, &amp;$errno, &amp;$errstr, 
$timeout);</DIV>
<DIV>&nbsp;</DIV>
<DIV>But I get a failure to connect:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:21235</DIV>
<DIV>Error 111 - connection refused.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Any suggestions?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks, Brendan</FONT></DIV></BODY></HTML>