Ejemplo n.º 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;
 }
Ejemplo n.º 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();
Ejemplo n.º 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();
 }
Ejemplo n.º 4
0
$daemon = new Daemon(function (Daemon $daemon, Control $control) {
    openlog($daemon->getOption('name'), LOG_PID | LOG_PERROR, LOG_LOCAL0);
    $control->flush(60);
});
$daemon->bind(Daemon::EVENT_SUCCESS, function () {
    syslog(LOG_INFO, 'Daemon was successfully finished');
});
$daemon->bind(Daemon::EVENT_ERROR | Daemon::EVENT_FAILURE, function (Context $context) {
    syslog(LOG_ERR, $context->exception->getMessage());
});
$daemon->bind(Daemon::EVENT_FINISH, function () {
    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();
Ejemplo n.º 5
0
<?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;
}
Ejemplo n.º 6
0
<?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->kill();
if (!$child->isRunning()) {
    echo 'Child was killed' . PHP_EOL;
}
Ejemplo n.º 7
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Action\Callback;
use Arara\Process\Child;
use Arara\Process\Control;
$child = new Child(new Callback(function (Control $control) {
    echo 'This child process will sleep for 0.5 seconds' . PHP_EOL;
    $control->flush(0.5);
    echo 'This child just woke up' . PHP_EOL;
}), new Control());
$child->start();
$child->wait();
if (!$child->isRunning()) {
    echo 'Child is not running anymore' . PHP_EOL;
}
Ejemplo n.º 8
0
<?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 'Child process is ' . $control->info()->getId() . PHP_EOL;
    $control->flush(1);
}), $control);
echo 'Parent process is ' . $control->info()->getId() . PHP_EOL;
$child->start();
if ($child->getStatus()->isSuccessful()) {
    echo 'Child successfully finished' . PHP_EOL;
}