Advertisement
Guest User

Dave Ingram

a guest
Nov 10th, 2009
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1.   protected static function processBatchTimesChunk($chunk, $timeout) {
  2.     $pid = pcntl_fork();
  3.     if ($pid>0) {
  4.       // parent
  5.       return;
  6.     }
  7.     // child or could not fork
  8.     foreach ($chunk as $NaPTAN) {
  9.       self::fetchData($NaPTAN, $timeout);
  10.     }
  11.     if ($pid != -1) exit;
  12.   }
  13.  
  14.   public static function preCacheTimes(array $NaPTANs, $threads=5, $timeout=15) {
  15.     if (!count($NaPTANs)) return array();
  16.     $chunks = array_chunk($NaPTANs, ceil(count($NaPTANs) / $threads));
  17.     // spawn threads
  18.     foreach ($chunks as $chunk) {
  19.       self::processBatchTimesChunk($chunk, $timeout);
  20.     }
  21.     // wait for completion
  22.     $status=0;
  23.     while (pcntl_wait($status, WNOHANG)>=0) { /* do nothing */ }
  24.   }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement