Page MenuHomePhabricator
Paste P1137

futures.php
ActivePublic

Authored by epriestley on May 14 2014, 1:58 PM.
Tags
None
Referenced Files
F154665: futures.php
May 14 2014, 1:58 PM
Subscribers
None
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$number_of_tasks = $argv[1];
$seconds_per_task = $argv[2];
$seconds_of_processing = $argv[3];
$futures = array();
for ($ii = 0; $ii < $number_of_tasks; $ii++) {
$futures[] = new ExecFuture('sleep %d', $seconds_per_task);
}
echo "[T = ".t()."] Starting {$number_of_tasks} tasks, ".
"which will take {$seconds_per_task} each, ".
"and require {$seconds_of_processing} seconds to process.\n";
foreach (Futures($futures) as $future) {
sleep($seconds_of_processing);
echo "[T = ".t()."] Completed a task.\n";
}
echo "[T = ".t()."] Done.\n";
function t() {
static $start;
if (!$start) {
$start = microtime(true);
}
return sprintf('%.1f', microtime(true) - $start);
}

Event Timeline

epriestley changed the title of this paste from untitled to futures.php.
epriestley updated the paste's language from autodetect to autodetect.