Completed
Branch master (a12146)
by Joao
06:36 queued 02:37
created
example_pool.php 3 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -5,48 +5,48 @@
 block discarded – undo
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
-	for ($i = 0; $i < 10; $i++)
11
-	{
12
-		echo "Hello from thread #$t, i=$i" . PHP_EOL;
13
-		sleep(1);
14
-	}
10
+    for ($i = 0; $i < 10; $i++)
11
+    {
12
+        echo "Hello from thread #$t, i=$i" . PHP_EOL;
13
+        sleep(1);
14
+    }
15 15
     echo "Ending thread #$t" . PHP_EOL;
16 16
 
17
-	return uniqid("Thread_{$t}_");
17
+    return uniqid("Thread_{$t}_");
18 18
 }
19 19
 
20 20
 
21 21
 try
22 22
 {
23
-	// Create a instance of the ThreadPool
24
-	$threadPool = new \ByJG\PHPThread\ThreadPool();
23
+    // Create a instance of the ThreadPool
24
+    $threadPool = new \ByJG\PHPThread\ThreadPool();
25 25
 
26
-	// Create the threads
26
+    // Create the threads
27 27
     for ($i = 0; $i < 10; $i++)
28 28
     {
29
-		// Queue a worker pointing to "Foo" function and pass the required parameters
29
+        // Queue a worker pointing to "Foo" function and pass the required parameters
30 30
         $threadPool->queueWorker('Foo', [ $i ]);
31 31
     }
32 32
 
33
-	// Starts all the threads in the queue
34
-	$threadPool->startWorkers();
33
+    // Starts all the threads in the queue
34
+    $threadPool->startWorkers();
35 35
 
36
-	// Wait until there is no more active workers
37
-	while($threadPool->activeWorkers() > 0)
38
-	{
39
-		echo "Active Workers : " . $threadPool->activeWorkers() . "\n";
40
-		sleep(1);
41
-	}
36
+    // Wait until there is no more active workers
37
+    while($threadPool->activeWorkers() > 0)
38
+    {
39
+        echo "Active Workers : " . $threadPool->activeWorkers() . "\n";
40
+        sleep(1);
41
+    }
42 42
 
43
-	// Get the return value from the thread.
44
-	foreach ($threadPool->getThreads() as $thid)
45
-	{
46
-		echo 'Result: ' . $threadPool->getThreadResult($thid) . "\n";
47
-	}
43
+    // Get the return value from the thread.
44
+    foreach ($threadPool->getThreads() as $thid)
45
+    {
46
+        echo 'Result: ' . $threadPool->getThreadResult($thid) . "\n";
47
+    }
48 48
 
49
-	echo "\n\nEnded!\n";
49
+    echo "\n\nEnded!\n";
50 50
 
51 51
 }
52 52
 catch (Exception $e)
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@  discard block
 block discarded – undo
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
 	{
12
-		echo "Hello from thread #$t, i=$i" . PHP_EOL;
12
+		echo "Hello from thread #$t, i=$i".PHP_EOL;
13 13
 		sleep(1);
14 14
 	}
15
-    echo "Ending thread #$t" . PHP_EOL;
15
+    echo "Ending thread #$t".PHP_EOL;
16 16
 
17 17
 	return uniqid("Thread_{$t}_");
18 18
 }
@@ -27,23 +27,23 @@  discard block
 block discarded – undo
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
-		echo "Active Workers : " . $threadPool->activeWorkers() . "\n";
39
+		echo "Active Workers : ".$threadPool->activeWorkers()."\n";
40 40
 		sleep(1);
41 41
 	}
42 42
 
43 43
 	// Get the return value from the thread.
44 44
 	foreach ($threadPool->getThreads() as $thid)
45 45
 	{
46
-		echo 'Result: ' . $threadPool->getThreadResult($thid) . "\n";
46
+		echo 'Result: '.$threadPool->getThreadResult($thid)."\n";
47 47
 	}
48 48
 
49 49
 	echo "\n\nEnded!\n";
@@ -51,6 +51,6 @@  discard block
 block discarded – undo
51 51
 }
52 52
 catch (Exception $e)
53 53
 {
54
-    echo 'Exception: ' . $e . PHP_EOL;
54
+    echo 'Exception: '.$e.PHP_EOL;
55 55
 }
56 56
 
Please login to merge, or discard this patch.
src/Thread.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
      */
74 74
     public function start()
75 75
     {
76
-        $this->_threadKey = 'thread_' . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999);
76
+        $this->_threadKey = 'thread_'.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999);
77 77
 
78 78
         if (($this->_pid = pcntl_fork()) == -1) {
79 79
             throw new RuntimeException('Couldn\'t fork the process');
Please login to merge, or discard this patch.
example.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
 // Method to be executed in a thread
5 5
 function Foo($t)
6 6
 {
7
-    echo "Starting thread #$t" . PHP_EOL;
7
+    echo "Starting thread #$t".PHP_EOL;
8 8
     
9 9
     sleep(1 * rand(1, 5));
10 10
     for ($i = 0; $i < 10; $i++) {
11
-        echo "Hello from thread #$t, i=$i" . PHP_EOL;
11
+        echo "Hello from thread #$t, i=$i".PHP_EOL;
12 12
         sleep(1);
13 13
     }
14
-    echo "Ending thread #$t" . PHP_EOL;
14
+    echo "Ending thread #$t".PHP_EOL;
15 15
 
16 16
     // Note: this line below require the file "config/cacheconfig.php" exists
17
-    return "$t: [[[[[[" . time() . "]]]]]]";
17
+    return "$t: [[[[[[".time()."]]]]]]";
18 18
 }
19 19
 
20 20
 try {
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 
52 52
     // Note: this line below require the file "config/cacheconfig.php" exists
53 53
     foreach ($t as $thread) {
54
-        echo "Result: " . $thread->getResult() . "\n";
54
+        echo "Result: ".$thread->getResult()."\n";
55 55
     }
56 56
     
57 57
 } catch (Exception $e) {
58
-    echo 'Exception: ' . $e . PHP_EOL;
58
+    echo 'Exception: '.$e.PHP_EOL;
59 59
 }
Please login to merge, or discard this patch.