Exemplo n.º 1
0
foreach ($urls as $url) {
    $u = new Gaia\Container(parse_url($url));
    if (!@fsockopen($u->host, $u->port)) {
        continue;
    }
    $status = TRUE;
    break;
}
if (!$status) {
    Tap::plan('skip_all', 'unable to connect to test job url: ' . $url);
}
Tap::plan(5);
$tube = '__test__';
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) {
Exemplo n.º 2
0
}
if (!@fsockopen('127.0.0.1', '11299')) {
    die("unable to connect to test job url\n");
}
$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("\nInstantiating job runner ... \n");
$runner = new Runner();
$nonce = new Nonce('test001');
$config = Job::config();
//$config->addConnection( new Pheanstalk('127.0.0.1', '11300' ) );
$config->setQueuePrefix('test');
//$config->addQueueRate('test*',10);
// set up a connection pool for the default.
$conn_pool = array();
$config->setBuilder(function ($job, array &$opts) use($nonce, &$conn_pool, $debugger) {
    $parts = new Gaia\Container(@parse_url($job->url));
    $uri = isset($parts->path) ? $parts->path : '/';
    if ($parts->query) {
        $uri = $uri . '?' . $parts->query;
    }
    if ($job->id) {
        $opts[CURLOPT_HTTPHEADER][] = 'X-Job-Id: ' . $job->id;