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 );
22
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+ */
59
610require '../vendor/autoload.php ' ;
711
812use skrtdev \async \Pool ;
913
10- $ pool = new Pool (10 );
14+ $ pool = new Pool ();
1115
1216for ($ i =0 ; $ i < 100 ; $ i ++) {
13- $ pool ->parallel (function () use ( $ i ) {
17+ $ pool ->parallel (function (int $ i ) {
1418 sleep (1 );
1519 print ("by the child n. $ i " .PHP_EOL );
16- });
20+ }, " my nice process name " , $ i );
1721}
1822
19- print ("OUT OF FOR " . PHP_EOL .PHP_EOL );
23+ print ("Out of for, doing some external work... " .PHP_EOL );
2024
21- function some_work ()
22- {
25+ for ($ i =0 ; $ i < 10000 ; $ i ++) {
2326 usleep (1000 );
2427}
2528
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- }
3129print ("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 );
32
43require '../vendor/autoload.php ' ;
54
65use skrtdev \async \Pool ;
76
8- $ pool = new Pool (100 );
7+ $ pool = new Pool ();
98
109for ($ i =0 ; $ i < 10 ; $ i ++) {
1110 $ pool ->parallel (function () use ($ i ) {
You can’t perform that action at this time.
0 commit comments