Beispiel #1
0
    private $_index = 0;
    private $_lastIsNull = false;
    public function fetchTask()
    {
        $task = $this->_doFetchTask();
        if ($task) {
            $this->_lastIsNull == false;
            return $task;
        }
        if (!$this->_lastIsNull) {
            $this->_lastIsNull = true;
            return null;
        }
        sleep(1);
        return null;
    }
    public function _doFetchTask()
    {
        $index = $this->_index;
        $this->_index++;
        if (!isset($this->_plan[$index])) {
            return null;
        }
        echo "new Task({$index}, \$this->_plan[{$index}]\n";
        return new Task($index, $this->_plan[$index]);
    }
}
$taskFactory = new TaskFactory();
$config = array('factoryMethod' => array($taskFactory, 'fetchTask'), 'quantity' => 3);
Comos\Qpm\Supervision\Supervisor::taskFactoryMode($config)->start();
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
$run = function () {
    $i = 3;
    while ($i--) {
        echo "#{$i} PID:" . posix_getpid() . "\n";
        sleep(1);
    }
};
$config = array('worker' => $run, 'quantity' => 3, 'maxRestartTimes' => 30);
Comos\Qpm\Supervision\Supervisor::oneForOne($config)->start();
Beispiel #3
0
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
$logFile = __FILE__ . '-simple-Logger.log';
Comos\Qpm\Log\Logger::useSimpleLogger($logFile);
echo "Execute 'tail {$logFile}' to see the lastest logs.\n";
$func = function () {
    $i = 3;
    while (--$i) {
        sleep(1);
    }
};
try {
    Comos\Qpm\Supervision\Supervisor::oneForOne(array('worker' => $func, 'quantity' => 3, 'maxRestartTimes' => 3))->start();
} catch (Exception $ex) {
    Comos\Qpm\Log\Logger::err($ex);
}
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
$run1 = function () {
    while (true) {
        echo "---run1,pid:" . \posix_getpid() . "\n";
        sleep(3);
        exit;
    }
};
$run2 = function () {
    while (true) {
        echo "+++run2,pid:" . \posix_getpid() . "\n";
        sleep(3);
        exit;
    }
};
$configs = array(array('worker' => $run1), array('worker' => $run2, 'quantity' => 2));
Comos\Qpm\Supervision\Supervisor::multiGroupOneForOne($configs)->start();
Beispiel #5
0
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Monolog\Formatter\NormalizerFormatter;
use Monolog\Formatter\LineFormatter;
$logFile = __FILE__ . '.log';
echo "Running... Use ctrl+c to quit.\nExecute 'tail {$logFile}' to see the lastest logs.\n";
$logger = new Logger('qpm');
$handler = new StreamHandler($logFile);
new LineFormatter();
$logger->pushHandler($handler);
$formatter = new LineFormatter();
$handler->setFormatter($formatter);
Comos\Qpm\Log\Logger::setLoggerImpl($logger);
function doSomething()
{
    sleep(1);
    throw new Exception('xxx');
}
Comos\Qpm\Supervision\Supervisor::oneForOne(array('worker' => 'doSomething'))->start();