note 101492 added to function.socket-write
| From: | revelable at hotmail dot com | Date: | Tue, 21 Dec 2010 01:08:08 +0000 |
| Subject: | note 101492 added to function.socket-write | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175084@lists.php.net to get a copy of this message | ||
Here we have the same function to write a socket but with improved performance.
If the messager are not larger, they will be written entirely with a single socket_write() call. And
is not needed to call the substr() function for the first bucle.
<?php
$st="Message to sent";
$length = strlen($st);
while (true) {
$sent = socket_write($socket, $st, $length);
if ($sent === false) {
break;
}
// Check if the entire message has been sented
if ($sent < $length) {
// If not sent the entire message.
// Get the part of the message that has not yet been sented as message
$st = substr($st, $sent);
// Get the length of the not sented part
$length -= $sent;
} else {
break;
}
}
?>
----
Server IP: 80.64.47.13
Probable Submitter: 217.217.180.153
----
Manual Page -- http://www.php.net/manual/en/function.socket-write.php
Edit -- https://master.php.net/note/edit/101492
Del: integrated -- https://master.php.net/note/delete/101492/integrated
Del: useless -- https://master.php.net/note/delete/101492/useless
Del: bad code -- https://master.php.net/note/delete/101492/bad+code
Del: spam -- https://master.php.net/note/delete/101492/spam
Del: non-english -- https://master.php.net/note/delete/101492/non-english
Del: in docs -- https://master.php.net/note/delete/101492/in+docs
Del: other reasons-- https://master.php.net/note/delete/101492
Reject -- https://master.php.net/note/reject/101492
Search -- https://master.php.net/manage/user-notes.php