本文整理汇总了PHP中Job::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Job::run方法的具体用法?PHP Job::run怎么用?PHP Job::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job::run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($path, $args = NULL)
{
$this->path = \Tester\Helpers::escapeArg($path);
$proc = proc_open("{$this->path} -n {$args} -v", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
$output = stream_get_contents($pipes[1]);
$this->error = trim(stream_get_contents($pipes[2]));
if (proc_close($proc)) {
throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $this->error));
} elseif (!preg_match('#^PHP (\\S+).*c(g|l)i#i', $output, $matches)) {
throw new \Exception("Unable to detect PHP version (output: {$output}).");
}
$this->version = $matches[1];
$this->cgi = strcasecmp($matches[2], 'g') === 0;
$this->arguments = $args;
$job = new Job(__DIR__ . '/info.php', $this, array('xdebug'));
$job->run();
$this->xdebug = !$job->getExitCode();
}
示例2: Job
function do_get_testchainedphp_hello_v1($job, $resp)
{
$content = json_encode("Hello from job");
// do internal hello1 which just appends it name to our content
$j = new Job($job);
$j->name("do_get_internalphp_hello1_v1");
$j->type(Job::JOB_SYNC);
$j->content($content);
$r = $j->run();
// create sync http rest job back to localhost which takes
// the output from previous job and adds its own name.
$j = $this->job_manager()->job(HttpClient::METHOD_POST, $job->base_uri() . "/hello2");
$j->content($r->content());
$j->headers($r->headers());
$r = $j->run();
$resp->content($r->content());
$resp->headers($r->headers());
return Worker::WORKER_SUCCESS;
}
示例3: executeJob
/**
* @param Job $job
* @param BufferingStatsdDataFactory $stats
* @param float $popTime
* @return array Map of status/error/timeMs
*/
private function executeJob(Job $job, $stats, $popTime)
{
$jType = $job->getType();
$msg = $job->toString() . " STARTING";
$this->logger->debug($msg);
$this->debugCallback($msg);
// Run the job...
$rssStart = $this->getMaxRssKb();
$jobStartTime = microtime(true);
try {
$status = $job->run();
$error = $job->getLastError();
$this->commitMasterChanges($job);
DeferredUpdates::doUpdates();
$this->commitMasterChanges($job);
} catch (Exception $e) {
MWExceptionHandler::rollbackMasterChangesAndLog($e);
$status = false;
$error = get_class($e) . ': ' . $e->getMessage();
MWExceptionHandler::logException($e);
}
// Commit all outstanding connections that are in a transaction
// to get a fresh repeatable read snapshot on every connection.
// Note that jobs are still responsible for handling slave lag.
wfGetLBFactory()->commitAll(__METHOD__);
// Clear out title cache data from prior snapshots
LinkCache::singleton()->clear();
$timeMs = intval((microtime(true) - $jobStartTime) * 1000);
$rssEnd = $this->getMaxRssKb();
// Record how long jobs wait before getting popped
$readyTs = $job->getReadyTimestamp();
if ($readyTs) {
$pickupDelay = max(0, $popTime - $readyTs);
$stats->timing('jobqueue.pickup_delay.all', 1000 * $pickupDelay);
$stats->timing("jobqueue.pickup_delay.{$jType}", 1000 * $pickupDelay);
}
// Record root job age for jobs being run
$root = $job->getRootJobParams();
if ($root['rootJobTimestamp']) {
$age = max(0, $popTime - wfTimestamp(TS_UNIX, $root['rootJobTimestamp']));
$stats->timing("jobqueue.pickup_root_age.{$jType}", 1000 * $age);
}
// Track the execution time for jobs
$stats->timing("jobqueue.run.{$jType}", $timeMs);
// Track RSS increases for jobs (in case of memory leaks)
if ($rssStart && $rssEnd) {
$stats->increment("jobqueue.rss_delta.{$jType}", $rssEnd - $rssStart);
}
if ($status === false) {
$msg = $job->toString() . " t={$timeMs} error={$error}";
$this->logger->error($msg);
$this->debugCallback($msg);
} else {
$msg = $job->toString() . " t={$timeMs} good";
$this->logger->info($msg);
$this->debugCallback($msg);
}
return array('status' => $status, 'error' => $error, 'timeMs' => $timeMs);
}