| @@ 5-18 (lines=14) @@ | ||
| 2 | require_once('vendor/autoload.php'); |
|
| 3 | ||
| 4 | // Method to be executed in a thread |
|
| 5 | function Foo($t) |
|
| 6 | { |
|
| 7 | echo "Starting thread #$t" . PHP_EOL; |
|
| 8 | ||
| 9 | sleep(1 * rand(1, 5)); |
|
| 10 | for ($i = 0; $i < 10; $i++) { |
|
| 11 | echo "Hello from thread #$t, i=$i" . PHP_EOL; |
|
| 12 | sleep(1); |
|
| 13 | } |
|
| 14 | echo "Ending thread #$t" . PHP_EOL; |
|
| 15 | ||
| 16 | // Note: this line below require the file "config/cacheconfig.php" exists |
|
| 17 | return "$t: [[[[[[" . time() . "]]]]]]"; |
|
| 18 | } |
|
| 19 | ||
| 20 | try { |
|
| 21 | $t = array(); |
|
| @@ 6-18 (lines=13) @@ | ||
| 3 | require_once('vendor/autoload.php'); |
|
| 4 | ||
| 5 | // Method to be executed in a thread |
|
| 6 | function Foo($t) |
|
| 7 | { |
|
| 8 | echo "Starting thread #$t" . PHP_EOL;; |
|
| 9 | sleep(1 * rand(1, 5)); |
|
| 10 | for ($i = 0; $i < 10; $i++) { |
|
| 11 | echo "Hello from thread #$t, i=$i" . PHP_EOL; |
|
| 12 | sleep(1); |
|
| 13 | } |
|
| 14 | echo "Ending thread #$t" . PHP_EOL; |
|
| 15 | ||
| 16 | return uniqid("Thread_{$t}_"); |
|
| 17 | } |
|
| 18 | ||
| 19 | ||
| 20 | try { |
|
| 21 | // Create a instance of the ThreadPool |
|