예제 #1
0
 public function testCallbackQueue()
 {
     $callback = function ($arg1) {
         file_put_contents(__DIR__ . '/artifacts/output', $arg1 . "\n", FILE_APPEND);
     };
     $callbackQueue = new Workman\CallbackQueue($callback);
     for ($c = 0; $c < 100; $c++) {
         $callbackQueue->push([$c]);
     }
     $callbackQueue->work(5);
     $lines = file(__DIR__ . '/artifacts/output');
     $this->assertEquals(100, count($lines));
     foreach ($lines as $line) {
         $trimmedLines[] = trim($line);
     }
     sort($trimmedLines);
     $this->assertEquals(range(0, 99), $trimmedLines);
 }
예제 #2
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
$callback = function ($arg1) {
    echo getmypid() . ": " . $arg1 . "\n";
};
$callbackQueue = new Workman\CallbackQueue($callback, 3);
for ($c = 0; $c < 100000; $c++) {
    $callbackQueue->push([$c]);
}
$callbackQueue->work(7);