-
I make a educational lesson with Async library. Want to figure out how to work in async mode properly. So I made a 3 scripts. All 3 scripts connect to database 12 times. First script finish work in 26 seconds Second script finish work in 26 seconds too I read documentation and found this
So I rewrote script and made 3 variant Could anybody why this script did not work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @Carsak, thanks for bringing this up 👍 First important thing to note is that the Loop::addTimer(0.5, React\Async\async(function () {
echo 'a';
sleep(1); // broken: using PHP's blocking sleep() for demonstration purposes
echo 'c';
}));
Loop::addTimer(1.0, function () {
echo 'b';
});
// prints "a" at t=0.5s
// prints "c" at t=1.5s: Correct timing, but wrong order
// prints "b" at t=1.5s: Triggered too late because it was blocked This means, You can read all about async and await in our reactphp/async documentation. I also gave a quick explanation on |
Beta Was this translation helpful? Give feedback.
thank you @SimonFrings
After of days analyst and searching I figure out 2 problems
so, how I solved my issue?
I am creating for each iteration new child process. So it is solved two problems, my code running in in parallel mode, each iteration blocks only own runtime
I uploaded my solution to Github, so everybody can check it
https://github.com/Carsak/php-react/pull/1/files