note 88921 added to function.socket-write

From: Date: Fri, 13 Feb 2009 10:16:21 +0000
Subject: note 88921 added to function.socket-write
Groups: php.notes 
Request: Send a blank email to php-notes+get-150614@lists.php.net to get a copy of this message
"socket_write() does not necessarily write all bytes from the given buffer." So I wrote the following code to correctly write message to the socket $message="Message to sent"; $len = strlen($message); $offset = 0; while ($offset < $len) { $sent = socket_write($socket, substr($message, $offset), $len-$offset); if ($sent === false) { // Error occurred, break the while loop break; } $offset += $sent; } if ($offset < $len) { $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); echo "SENDING ERROR: $errormsg"; } else { // Data sent ok } ---- Server IP: 82.177.164.100 Probable Submitter: 193.239.136.30 ---- Manual Page -- http://www.php.net/manual/en/function.socket-write.php Edit -- https://master.php.net/note/edit/88921 Del: integrated -- https://master.php.net/note/delete/88921/integrated Del: useless -- https://master.php.net/note/delete/88921/useless Del: bad code -- https://master.php.net/note/delete/88921/bad+code Del: spam -- https://master.php.net/note/delete/88921/spam Del: non-english -- https://master.php.net/note/delete/88921/non-english Del: in docs -- https://master.php.net/note/delete/88921/in+docs Del: other reasons-- https://master.php.net/note/delete/88921 Reject -- https://master.php.net/note/reject/88921 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150614) next »