File tree Expand file tree Collapse file tree 2 files changed +16
-23
lines changed Expand file tree Collapse file tree 2 files changed +16
-23
lines changed Original file line number Diff line number Diff line change 1
- <?php
1
+ <?php declare (ticks= 1 );
2
2
3
- error_reporting (E_ALL );
4
- declare (ticks=1 ); // IN THIS CASE THIS IS NECESSARY
3
+ /**
4
+ * without ticks, this script won't
5
+ * continue to execute parallels
6
+ * when inside the for, it will
7
+ * only finish the pool by destructor
8
+ */
5
9
6
10
require '../vendor/autoload.php ' ;
7
11
8
12
use skrtdev \async \Pool ;
9
13
10
- $ pool = new Pool (10 );
14
+ $ pool = new Pool ();
11
15
12
16
for ($ i =0 ; $ i < 100 ; $ i ++) {
13
- $ pool ->parallel (function () use ( $ i ) {
17
+ $ pool ->parallel (function (int $ i ) {
14
18
sleep (1 );
15
19
print ("by the child n. $ i " .PHP_EOL );
16
- });
20
+ }, " my nice process name " , $ i );
17
21
}
18
22
19
- print ("OUT OF FOR " . PHP_EOL .PHP_EOL );
23
+ print ("Out of for, doing some external work... " .PHP_EOL );
20
24
21
- function some_work ()
22
- {
25
+ for ($ i =0 ; $ i < 10000 ; $ i ++) {
23
26
usleep (1000 );
24
27
}
25
28
26
- print ("Doing some external work... " .PHP_EOL );
27
- for ($ i =0 ; $ i < 10000 ; $ i ++) {
28
- #print("SHOULD TICK".PHP_EOL);
29
- some_work ();
30
- }
31
29
print ("External work finished... " .PHP_EOL );
32
- exit ;
33
- sleep (5 );
34
- var_dump ($ pool );
35
- var_dump (Pool::$ cores_count );
36
- #var_dump($pool->$max_childs);
37
- sleep (1 );
30
+
31
+ // here destructor is fired, and it will internally call $pool->wait()
Original file line number Diff line number Diff line change 1
- <?php
2
- declare (ticks=1 );
1
+ <?php declare (ticks=1 );
3
2
4
3
require '../vendor/autoload.php ' ;
5
4
6
5
use skrtdev \async \Pool ;
7
6
8
- $ pool = new Pool (100 );
7
+ $ pool = new Pool ();
9
8
10
9
for ($ i =0 ; $ i < 10 ; $ i ++) {
11
10
$ pool ->parallel (function () use ($ i ) {
You can’t perform that action at this time.
0 commit comments