Ejemplo n.º 1
0
 public function testShouldOverwriteOptions()
 {
     $daemon = new Daemon(function () {
     });
     $daemon->setOption('lock_dir', '/tmp');
     $this->assertSame('/tmp', $daemon->getOption('lock_dir'));
 }
Ejemplo n.º 2
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Action\Daemon;
use Arara\Process\Child;
use Arara\Process\Context;
use Arara\Process\Control;
$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);
    }