for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ackintosh\Snidel;
use Ackintosh\Snidel\IpcKey;
use Opis\Closure\SerializableClosure;
class ResultQueue
{
const RESULT_MAX_SIZE = 5120;
private $dequeuedCount = 0;
public function __construct($ownerPid)
$this->ownerPid = $ownerPid;
ownerPid
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->ipcKey = new IpcKey($ownerPid, 'snidel_result_' . uniqid((string) mt_rand(1, 100), true));
ipcKey
$this->id = msg_get_queue($this->ipcKey->generate());
id
}
public function enqueue($result)
return msg_send($this->id, 1, serialize($result));
public function dequeue()
$this->dequeuedCount++;
$msgtype = $message = null;
$success = msg_receive($this->id, 1, $msgtype, self::RESULT_MAX_SIZE, $message);
if (!$success) {
throw new \RuntimeException('failed to dequeue result');
return unserialize($message);
/**
* @return int
*/
public function dequeuedCount()
return $this->dequeuedCount;
public function __destruct()
if ($this->ipcKey->isOwner(getmypid())) {
$this->ipcKey->delete();
return msg_remove_queue($this->id);
}// @codeCoverageIgnore
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: