예제 #1
0
Job::config()->addConnection(new Pheanstalk('127.0.0.1', '11300'));
Job::config()->setQueuePrefix('test');
$runner = new Runner();
$ct = $runner->flush($queue);
print "\nJOBS flushed from the queue before starting: {$ct}\n";
for ($i = 0; $i < 100; $i++) {
    $start = microtime(TRUE);
    $job = new Job($url);
    $job->queue = $queue;
    $id = $job->store();
    $elapsed = number_format(microtime(TRUE) - $start, 3);
    print "\nSTORE " . $id . ' ' . $elapsed . 's';
}
$start = microtime(TRUE);
$runner->watch($queue);
$runner->setTimelimit(20);
$runner->setMax(10);
$runner->attachDebugger($debugger = function ($v) {
    if ($v instanceof Exception) {
        $v = $v->__toString();
    }
    if (!is_scalar($v)) {
        strval($v);
    }
    $dt = "\n[" . date('H:i:s') . '] ';
    echo $dt . str_replace("\n", $dt, trim($v));
});
$debugger("kicking off job runner ...\n---------------------");
Job::config()->setHandler(function (Http\Request $request) use($debugger) {
    $out = "\nHTTP";
    if ($request->id) {
예제 #2
0
    if (!isset($ct)) {
        $ct = 0;
    }
    $stats = $runner->stats();
    $diff = $ct - $stats['processed'];
    $iterations = 1000 - $diff;
    for ($i = 0; $i < $iterations; $i++) {
        $job = new Job('http://127.0.0.1:11299/job.php?signed=1&ct=' . $ct . '&s=' . microtime(TRUE));
        $job->queue = $queue;
        $id = $job->store();
        $ct++;
        $debugger(sprintf("STORE - %s: %s", $id, $job->url));
    }
});
$runner->watch($queue);
$runner->setTimelimit(300);
$runner->setMax(10);
//$runner->attachDebugger( $debugger );
declare (ticks=1);
$start = microtime(TRUE);
// signal handler function
$sig_handler = function ($signo) use($runner, $start, $debugger, $start) {
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
        case SIGHUP:
            // handle shutdown tasks
            $debugger("EXITING ... \nFinishing jobs in queue ...");
            sleep(1);
            $runner->shutdown();
            $elapsed = number_format(microtime(TRUE) - $start, 3);