Page MenuHomePhabricator
Paste P1140

Fork of P1137 futures.php
ActivePublic

Authored by hach-que on May 14 2014, 10:48 PM.
Tags
None
Referenced Files
F154831: Fork_of_P1137_futures.php
May 14 2014, 10:48 PM
Subscribers
None
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$number_of_tasks = 10;
$number_wait = array(5, 5, 5, 5, 1, 1, 1, 1, 1, 1);
$process_wait = array(3, 3, 3, 3, 3, 0, 0, 0, 0, 0);
$futures = array();
for ($ii = 0; $ii < $number_of_tasks; $ii++) {
$amount = $number_wait[$ii];
echo "sleep ".$amount."\n";
$futures[$ii] = new ExecFuture('sleep %d', $amount);
}
echo "[T = ".t()."] Starting 10 tasks.\n";
foreach (Futures($futures)->limit(4) as $ii => $future) {
if ($process_wait[$ii] > 0) {
echo "wait ".$process_wait[$ii]."\n";
$st = microtime(true);
while (microtime(true) - $st < $process_wait[$ii]) {
sleep(microtime(true) - $st);
}
}
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

hach-que changed the title of this paste from untitled to Fork of P1137 futures.php.
hach-que updated the paste's language from autodetect to autodetect.