@@ -6,17 +6,17 @@ discard block |
||
6 | 6 | // Method to be executed in a thread |
7 | 7 | public function bar($t) |
8 | 8 | { |
9 | - echo "Starting thread #$t" . PHP_EOL; |
|
9 | + echo "Starting thread #$t".PHP_EOL; |
|
10 | 10 | |
11 | 11 | sleep(1 * rand(1, 5)); |
12 | 12 | for ($i = 0; $i < 10; $i++) { |
13 | - echo "Hello from thread #$t, i=$i" . PHP_EOL; |
|
13 | + echo "Hello from thread #$t, i=$i".PHP_EOL; |
|
14 | 14 | sleep(1); |
15 | 15 | } |
16 | - echo "Ending thread #$t" . PHP_EOL; |
|
16 | + echo "Ending thread #$t".PHP_EOL; |
|
17 | 17 | |
18 | 18 | // Note: this line below require the file "config/cacheconfig.php" exists |
19 | - return "$t: [[[[[[" . time() . "]]]]]]"; |
|
19 | + return "$t: [[[[[[".time()."]]]]]]"; |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | |
48 | 48 | // Note: this line below require the file "config/cacheconfig.php" exists |
49 | 49 | foreach ($t as $thread) { |
50 | - echo "Result: " . $thread->getResult() . "\n"; |
|
50 | + echo "Result: ".$thread->getResult()."\n"; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } catch (Exception $e) { |
54 | - echo 'Exception: ' . $e . PHP_EOL; |
|
54 | + echo 'Exception: '.$e.PHP_EOL; |
|
55 | 55 | } |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | // Method to be executed in a thread |
8 | 8 | public function bar($t) |
9 | 9 | { |
10 | - echo "Starting thread #$t" . PHP_EOL; |
|
10 | + echo "Starting thread #$t".PHP_EOL; |
|
11 | 11 | sleep(1 * rand(1, 5)); |
12 | 12 | for ($i = 0; $i < 10; $i++) { |
13 | - echo "Hello from thread #$t, i=$i" . PHP_EOL; |
|
13 | + echo "Hello from thread #$t, i=$i".PHP_EOL; |
|
14 | 14 | sleep(1); |
15 | 15 | } |
16 | - echo "Ending thread #$t" . PHP_EOL; |
|
16 | + echo "Ending thread #$t".PHP_EOL; |
|
17 | 17 | |
18 | 18 | return uniqid("Thread_{$t}_"); |
19 | 19 | } |
@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | // Wait until there is no more active workers |
39 | 39 | // You can use $threadPool->waitWorkers() instead the loop below |
40 | 40 | while ($threadPool->activeWorkers() > 0) { |
41 | - echo "Active Workers : " . $threadPool->activeWorkers() . "\n"; |
|
41 | + echo "Active Workers : ".$threadPool->activeWorkers()."\n"; |
|
42 | 42 | sleep(1); |
43 | 43 | } |
44 | 44 | |
45 | 45 | // Get the return value from the thread. |
46 | 46 | foreach ($threadPool->getThreads() as $thid) { |
47 | - echo 'Result: ' . $threadPool->getThreadResult($thid) . "\n"; |
|
47 | + echo 'Result: '.$threadPool->getThreadResult($thid)."\n"; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | echo "\n\nEnded!\n"; |
51 | 51 | |
52 | 52 | } catch (Exception $e) { |
53 | - echo 'Exception: ' . $e . PHP_EOL; |
|
53 | + echo 'Exception: '.$e.PHP_EOL; |
|
54 | 54 | } |
55 | 55 |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function execute() |
56 | 56 | { |
57 | - $this->threadKey = 'thread_' . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999); |
|
57 | + $this->threadKey = 'thread_'.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999); |
|
58 | 58 | |
59 | 59 | if (($this->pid = pcntl_fork()) == -1) { |
60 | 60 | throw new RuntimeException('Couldn\'t fork the process'); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | try { |
77 | - $return = call_user_func_array($callable, (array)$args); |
|
77 | + $return = call_user_func_array($callable, (array) $args); |
|
78 | 78 | |
79 | 79 | if (!is_null($return)) { |
80 | 80 | $this->saveResult($return); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace ByJG\PHPThread\Handler; |
4 | 4 | |
5 | -use ByJG\Cache\CacheContext; |
|
6 | 5 | use ByJG\Cache\Engine\ShmopCacheEngine; |
7 | 6 | use RuntimeException; |
8 | 7 |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | return $this->loader; |
38 | 38 | } |
39 | 39 | |
40 | - $path = __DIR__ . '/../../vendor/autoload.php'; |
|
40 | + $path = __DIR__.'/../../vendor/autoload.php'; |
|
41 | 41 | if (!file_exists($path)) { |
42 | - $path = __DIR__ . '/../../../../autoload.php'; |
|
42 | + $path = __DIR__.'/../../../../autoload.php'; |
|
43 | 43 | if (!file_exists($path)) { |
44 | 44 | throw new \RuntimeException("Autoload path '$path' not found"); |
45 | 45 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | try { |
65 | - $this->result = call_user_func_array($callable, (array)$this->args); |
|
65 | + $this->result = call_user_func_array($callable, (array) $this->args); |
|
66 | 66 | // Executed only in PHP 7, will not match in PHP 5.x |
67 | 67 | } catch (\Throwable $ex) { |
68 | 68 | $this->result = $ex; |
@@ -68,7 +68,7 @@ |
||
68 | 68 | ); |
69 | 69 | } else { |
70 | 70 | throw new RuntimeException( |
71 | - 'PHP need to be compiled with ZTS extension or compiled with the --enable-pcntl. ' . |
|
71 | + 'PHP need to be compiled with ZTS extension or compiled with the --enable-pcntl. '. |
|
72 | 72 | 'Windows is not supported.' |
73 | 73 | ); |
74 | 74 | } |