Hi All, I'm a newbie to PHP. Just started to use it for a week and I just subscribed to this mailing list.
I have a problem with socket reading using fread. What I'm doing is .. calling fsockopen to open a socket. Then call fwrite to send my data and then call fread for 4 bytes. My Server is supposed to send me the length of actual data in those 4 bytes and then I do another freadto get the actual data. It's working fine but, sometimes, I'm closing the socket before receiving any data. On the server side I'm getting an error like "peer terminated connection can not send data". I called socket_get_status to see if it's timing out but its not. However, I set the timeout period to 10 seconds in the call to fsockopen function. Still no avail. Is there any way I can check if there's any error with fread ? Thanks in advance for any help cheers R'twick My code is below : <<<<<<<<<<<<<< CODE >>>>>>>>>>>>>>>>> $socket = fsockopen($Host, $Port,$result,$errstr,10); if ($result != 0) { $ErrorMsg = "can not connect to Host. Reason: ($result) " . strerror($result); $ErrorMsg .= ". Please Contact SysAdmin"; } else { $result = fwrite ($socket, $msg, strlen ($msg)); $fp = fopen("log/nma_".date("Y-m-d").".log","a"); if ($result < 0 ) { $ErrorMsg = "can not send request to Host. Reason: ($result) " . strerror($result); $ErrorMsg .= ". Please Contact SysAdmin"; } else { $ResponseLine=fread($socket, 4); $socketstatus=socket_get_status($socket); if ($socketstatus["eof"] | $socketstatus["timed_out"]) { $ErrorMsg = "Host Timed Out". } } $RespLength=ord($ResponseLine[2])*256+ord($ResponseLine[3]); $Response .= $ResponseLine; $ResponseLine=fread($socket, $RespLength-4); $Response .= $ResponseLine; } $socketstatus=socket_get_status($socket); if ( $socketstatus["timed_out"]) { $ErrorMsg = "Host Timed Out". } fclose($socket); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]