Page MenuHomePhabricator

Fork_of_P1137_futures.php

Authored By
hach-que
May 14 2014, 10:48 PM
Size
961 B
Referenced Files
None
Subscribers
None

Fork_of_P1137_futures.php

#!/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);
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/iy/ff/drgpuer2u44ttcvq
Default Alt Text
Fork_of_P1137_futures.php (961 B)

Event Timeline