@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | // Method to be executed in a thread |
| 6 | 6 | function Foo($t) |
| 7 | 7 | { |
| 8 | - echo "Starting thread #$t" . PHP_EOL;; |
|
| 8 | + echo "Starting thread #$t" . PHP_EOL; ; |
|
| 9 | 9 | sleep(1 * rand(1, 5)); |
| 10 | 10 | for ($i = 0; $i < 10; $i++) |
| 11 | 11 | { |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | for ($i = 0; $i < 10; $i++) |
| 28 | 28 | { |
| 29 | 29 | // Queue a worker pointing to "Foo" function and pass the required parameters |
| 30 | - $threadPool->queueWorker('Foo', [ $i ]); |
|
| 30 | + $threadPool->queueWorker('Foo', [$i]); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // Starts all the threads in the queue |
| 34 | 34 | $threadPool->startWorkers(); |
| 35 | 35 | |
| 36 | 36 | // Wait until there is no more active workers |
| 37 | - while($threadPool->activeWorkers() > 0) |
|
| 37 | + while ($threadPool->activeWorkers() > 0) |
|
| 38 | 38 | { |
| 39 | 39 | echo "Active Workers : " . $threadPool->activeWorkers() . "\n"; |
| 40 | 40 | sleep(1); |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | echo "\n\nEnded!\n"; |
| 50 | 50 | |
| 51 | -} |
|
| 52 | -catch (Exception $e) |
|
| 51 | +} catch (Exception $e) |
|
| 53 | 52 | { |
| 54 | 53 | echo 'Exception: ' . $e . PHP_EOL; |
| 55 | 54 | } |