note 38817 deleted from function.socket-write by nlopess
| From: | nlopess@php.net | Date: | Wed, 07 Jan 2004 19:52:36 +0000 |
| Subject: | note 38817 deleted from function.socket-write by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63106@lists.php.net to get a copy of this message | ||
Note Submitter: muti@afterglo.ws
----
I have seen a lot of people misusing socket_write(). They assume that all the data will be
transferred in one call. Here is the proper way to send data using socket_write().
$totalToSend = strlen($data);
$sent = 0;
while($sent < $totalToSend) {
$i = socket_write($socket,$data);
if($i === FALSE) {
die('Error: '.socket_strerror(socket_last_error())."\n");
}
$sent += $i;
$data = substr($data,$i);
}