note 37279 added to function.fsockopen
| From: | martinatbangdotca at rn2 dot php dot net | Date: | Sat, 08 Nov 2003 15:15:55 +0000 |
| Subject: | note 37279 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60142@lists.php.net to get a copy of this message | ||
I had trouble keeping a tcp socket open in a telnet-like fashion. Since the server I connected to
never returned an end of file, socket_get_status (unread_bytes) always read "1", I could
never issue other commands through fputs.
The first solution was to simply close and re-open the socket (too slow, in this case).
What I cam up with is, once I am certain the server is done with its output:
socket_set_timeout( $connection, 0 );
fgets( $connection, 100 );
socket_set_timeout( $connection, SOCKET_TIMEOUT );
This forces a timeout and seems to "clean" the connection, and fputs statements are
properly handled after this point. (SOCKET_TIMEOUT is obviously a constant defined somewhere else).
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37279
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37279&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37279&report=yes
Search -- http://master.php.net/manage/user-notes.php