
Dave Ingram
By: a guest on
Nov 10th, 2009 | syntax:
PHP | size: 0.72 KB | hits: 37 | expires: Never
protected static function processBatchTimesChunk($chunk, $timeout) {
$pid = pcntl_fork();
if ($pid>0) {
// parent
return;
}
// child or could not fork
foreach ($chunk as $NaPTAN) {
self::fetchData($NaPTAN, $timeout);
}
}
public static
function preCacheTimes
(array $NaPTANs, $threads=5
, $timeout=15
) {
// spawn threads
foreach ($chunks as $chunk) {
self::processBatchTimesChunk($chunk, $timeout);
}
// wait for completion
$status=0;
while (pcntl_wait($status, WNOHANG)>=0) { /* do nothing */ }
}