kali707 Posted February 22, 2011 Share Posted February 22, 2011 hi guys, Just created my id on this forum. posting for the first time. The socket server does not send an EOF. Instead it sends a code to signal the end of the data. In the following code socket is opened without any problems. fputs works fine. But when the while loop is executed $info['timed_out'] is FALSE for each iteration as long as $info['unread_bytes'] != 0. In the last iteration $info['timed_out'] becomes TRUE (dont' know why). So, in the last iteration data does not get appeneded to $resp_all. What I am trying to do is to make sure that I have read all the data through the socket until that end-of-data signal/code is received (there is no EOF sent by the server). So I am trying to make sure that the data is not half-read or incomplete. If there is a timeout reading the data it should try again (at least 3 times). If you have any other suggestions/ideas to accomplish this please let me know. $fp = fsockopen($host, $port, $errno, $errdesc, 5); fputs($fp, $msg); $tryCnt = 1; stream_set_timeout($fp, 35); while ($tryCnt <= 3) { $rsp = fgets($fp, 1024); $info = stream_get_meta_data($fp); if ($info['timed_out']) { $tryCnt += 1; continue; } $rsp_all .= $rsp; # check for end of data signal and if there is, then break out } Link to comment https://forums.phpfreaks.com/topic/228499-stream_set_timeout-stream_get_meta_data/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.