note 48514 deleted from function.feof by nlopess

From: Date: Tue, 28 Dec 2004 08:39:31 +0000
Subject: note 48514 deleted from function.feof by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82388@lists.php.net to get a copy of this message
Note Submitter: fernando at dragoncs dot com ---- If your working on sockets some time you need to add some time out too so the server does not crash, it happend on my unix server also some time some data didn´t get right so I found this code. Apparently feof is only for if the socket is closed. If there is no data being sent then you are responsible for determining that. Works on PHP 5.0 <?php $err_no = 0; $err_str = ""; $url = "example.com" $port="30" $fp = fsockopen( $url,$port, &$err_no, &$err_str); stream_set_timeout($fp, 2); while ( !feof($fp)) { $read = fgets($fp, 1024); if ($read==false ) break; echo "Read: {$data} <BR>"; flush(); }//While fputs($fp, "QUIT"); echo fgets($fp, 1024); fclose($fp); ?> ---- Reason: useless example

« previous php.notes (#82388) next »