--- /dev/null
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "371512141531f38a907ed1a5fbe3055b",
+ "packages": [],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": ">=5.6.0"
+ },
+ "platform-dev": [],
+ "plugin-api-version": "2.2.0"
+}
--- /dev/null
+<?xml version="1.0"?>
+<psalm
+ errorLevel="2"
+ resolveFromConfigFile="true"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://getpsalm.org/schema/config"
+ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
+>
+ <projectFiles>
+ <directory name="src" />
+ <ignoreFiles>
+ <directory name="vendor" />
+ </ignoreFiles>
+ </projectFiles>
+</psalm>
abstract class Daemon extends Thread
{
+ /** */
public function start()
{
if ($this->isRunning()) {
$childpid = 256*256-1;
}
if ($childpid != 0) { // Push Child-PID from Starter-Thread
- $data = chr(floor($childpid / 256)).chr($childpid % 256);
+ $data = chr((int)(floor($childpid / 256))).chr($childpid % 256);
$fifo = fopen($fifo_file, 'w');
fwrite($fifo, $data);
exit();
}
}
-}
\ No newline at end of file
+}
namespace Graphit\Concurrent;
-class MainThread extends Thread
-{
- public function getChildren()
- {
- return parent::getChildren();
- }
-
- abstract function run();
-}
\ No newline at end of file
+class MainThread extends Thread { }
/** @var string */
protected $pidfile;
+ /**
+ * @param string $pidfile
+ */
public function __construct($pidfile)
{
$this->pidfile = $pidfile;
if (file_exists($this->pidfile)) {
- $this->pid = trim(file_get_contents($this->pidfile));
+ $this->pid = (int)(trim(file_get_contents($this->pidfile)));
}
}
+ /** */
public function isRunning()
{
if ( !$this->pid){
if (file_exists($this->pidfile)) {
- $this->pid = trim(file_get_contents($this->pidfile));
+ $this->pid = (int)(trim(file_get_contents($this->pidfile)));
}
}
$running = parent::isRunning();
return $running;
}
+ /** */
public function stop()
{
while ($this->isRunning()) {
}
}
+ /** */
public function setup()
{
parent::setup();
if ($this->isRunning()) {
- @file_put_contents($this->pidfile, $this->pid);
+ @file_put_contents($this->pidfile, (string)$this->pid);
}
}
+ /** */
public function teardown()
{
if ($this->isRunning()) {
abstract class Thread
{
- /** @var integer */
+ /** @var int|null */
protected $pid;
/** @var boolean */
protected $stopped = false;
+ /** @var bool */
+ private $daemon;
+
/** @var \Graphit\Concurrent\Thread[] */
protected $children = array();
- /** @var \Graphit\Concurrent\Thread */
+ /** @var Thread */
protected static $current;
/**
*/
public static function getCurrent()
{
- if ( !isset(Thread::$current)) {
+ if (!Thread::$current instanceof Thread) {
Thread::makeCurrent(new MainThread);
}
if (Thread::$current->pid !== posix_getpid()) {
return Thread::$current;
}
+ /**
+ * @return void
+ */
protected static function makeCurrent(Thread $current)
{
Thread::$current = $current;
pcntl_signal(SIGCHLD, array(Thread::$current, 'chldHandler'));
}
+ /**
+ * @return void
+ */
protected function termHandler()
{
$this->stopped = true;
}
+ /**
+ * @return void
+ */
protected function chldHandler()
{
while (($childpid = pcntl_waitpid(-1, $status, WNOHANG)) > 0) {
* Gibt die Prozess-Id des Threads zurück. Gibt nur den richtigen Wert zurück,
* solange $this->isRunning() === true.
*
- * @return integer
+ * @return int|null
*/
public function getPid()
{
return $this->children;
}
+ /**
+ * @return bool
+ */
public function isDaemon()
{
- return $this->_daemon;
+ return $this->daemon;
}
+ /**
+ * @param bool $daemon
+ *
+ * @return void
+ */
public function setDaemon($daemon)
{
- $this->_daemon = true == $daemon;
+ $this->daemon = !!$daemon;
}
/**
/**
* Started den Thread
*
- * @return boolean
+ * @return bool|null
*/
public function start()
{
}
}
+ /**
+ * @return void
+ */
public function setup() { }
- abstract public function run();
+ /**
+ * @return void
+ */
+ public function run() { }
+ /**
+ * @return void
+ */
public function teardown() { }
}