note 37279 deleted from function.fsockopen by nlopess

From: Date: Tue, 16 Dec 2003 14:57:25 +0000
Subject: note 37279 deleted from function.fsockopen by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62055@lists.php.net to get a copy of this message
Note Submitter: martin at bang dot ca ---- 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).

« previous php.notes (#62055) next »