示例#1
0
 /**
  * @see PHPFluent\EventManager\Listener::execute()
  */
 public function execute(Event $event, array $context = array())
 {
     $child = new Child($this->action, new Control());
     $child->start();
     return $child;
 }
示例#2
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Action\Action;
use Arara\Process\Action\Callback;
use Arara\Process\Child;
use Arara\Process\Context;
use Arara\Process\Control;
$action = new Callback(function () {
    trim(['A PHP error occours']);
});
$action->bind(Action::EVENT_ERROR, function (Context $context) {
    echo json_encode($context->toArray(), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL;
});
$control = new Control();
$child = new Child($action, $control);
$child->start();
$child->wait();
示例#3
0
 public function testShouldExitAsOneWhenExecuteThrowsAnException()
 {
     $action = $this->action->getMock();
     $action->expects($this->any())->method('execute')->will($this->throwException(new \Exception('Whatever')));
     $control = $this->control->getMock();
     $control->expects($this->any())->method('info')->will($this->returnValue($this->controlInfo->getMock()));
     $control->expects($this->any())->method('signal')->will($this->returnValue($this->controlSignal->getMock()));
     $control->expects($this->once())->method('quit')->with(1);
     $child = new Child($action, $control);
     $child->start();
 }
示例#4
0
    closelog();
});
$daemon->setOption('lock_dir', __DIR__);
$control = new Control();
$process = new Child($daemon, $control);
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);