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()) {
$senditem = $sendQueue->shift();
$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;
}
}
}
?>