Skip to content

Commit a9bd320

Browse files
committed
update examples
1 parent 63c8ea1 commit a9bd320

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

examples/concurrent.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
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

610
require '../vendor/autoload.php';
711

812
use skrtdev\async\Pool;
913

10-
$pool = new Pool(10);
14+
$pool = new Pool();
1115

1216
for ($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-
}
3129
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()

examples/while.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
<?php
2-
declare(ticks=1);
1+
<?php declare(ticks=1);
32

43
require '../vendor/autoload.php';
54

65
use skrtdev\async\Pool;
76

8-
$pool = new Pool(100);
7+
$pool = new Pool();
98

109
for ($i=0; $i < 10; $i++) {
1110
$pool->parallel(function () use ($i) {

0 commit comments

Comments
 (0)