note 116422 added to class.splqueue

From: Date: Wed, 31 Dec 2014 04:49:17 +0000
Subject: note 116422 added to class.splqueue
Groups: php.notes 
Request: Send a blank email to php-notes+get-201285@lists.php.net to get a copy of this message
To expand on the comment about push and pop: You can use shift/unshift and push/pop to dequeue/undequeue and queue/unqueue respectively. Really handy for those applications that use sockets where you might not know you can't send data until you attempt to. for example, this is a function for an application that will un-dequeue the remainder of the data if socket_write indicated it did not write the entire contents of the provided data. <?php function processSendQueue($socket, $sendQueue) { while (!$sendQueue->isEmpty()) { //shift() is the same as dequeue() $senditem = $sendQueue->shift(); //returns the number of bytes written. $rtn = socket_write($socket, $senditem); if ($rtn === false) { $sendQueue->unshift($senditem); throw new exception("send error: " . socket_last_error($socket)); return; } if ($rtn < strlen($senditem) { $sendQueue->unshift(substr($senditem, $rtn); break; } } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 24.19.215.105 ---- Manual Page -- http://php.net/manual/en/class.splqueue.php Edit -- https://master.php.net/note/edit/116422 Del: integrated -- https://master.php.net/note/delete/116422/integrated Del: useless -- https://master.php.net/note/delete/116422/useless Del: bad code -- https://master.php.net/note/delete/116422/bad+code Del: spam -- https://master.php.net/note/delete/116422/spam Del: non-english -- https://master.php.net/note/delete/116422/non-english Del: in docs -- https://master.php.net/note/delete/116422/in+docs Del: other reasons-- https://master.php.net/note/delete/116422 Reject -- https://master.php.net/note/reject/116422 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201285) next »