try { $args = $_SERVER['argv']; $script = array_shift($args); $usageMessage = sprintf('php %s {start|stop|status}', $script); if (empty($args)) { throw new DomainException($usageMessage); } $action = array_shift($args); switch ($action) { case 'start': $process->start(); fwrite(STDOUT, 'Started' . PHP_EOL); break; case 'stop': $process->terminate(); fwrite(STDOUT, 'Stopped' . PHP_EOL); break; case 'status': fwrite(STDOUT, 'Daemon is ' . ($process->isRunning() ? '' : 'not ') . 'running' . PHP_EOL); break; default: throw new DomainException($usageMessage); } } catch (DomainException $exception) { fwrite(STDERR, $exception->getMessage() . PHP_EOL); exit(1); } catch (Exception $exception) { fwrite(STDERR, $exception->getMessage() . PHP_EOL); fwrite(STDERR, $exception->getTraceAsString() . PHP_EOL); exit(2); }
public function testShouldReturnAsIsNotRunningWhenThereIsNoDefinedProcess() { $child = new Child($this->action->getMock(), $this->control->getMock()); $this->assertFalse($child->isRunning()); }
<?php declare (ticks=1); require_once __DIR__ . '/../vendor/autoload.php'; use Arara\Process\Action\Callback; use Arara\Process\Child; use Arara\Process\Control; $control = new Control(); $child = new Child(new Callback(function (Control $control) { echo 'This child process will sleep for 5 seconds' . PHP_EOL; $control->flush(5); echo 'This child just woke up' . PHP_EOL; }), $control); $child->start(); $control->flush(0.5); if ($child->isRunning()) { echo 'Child is running' . PHP_EOL; } $child->terminate(); if (!$child->isRunning()) { echo 'Child was terminated' . PHP_EOL; }