The problem is simple. I want to continuously execute a function while I wait for another task to finish, like in this silly example:
#!/usr/bin/env php
<?php
$timer = function() {
static $seconds = 0;
while(1) {
sleep(1);
echo "\r", $seconds++;
}
}
$timer(); // I want to run this in parallel
$service = new Service();
$response = $service->goGetSomething('from far far away');
// I want to kill the timer here
I do parallel processing with other languages all the time, but have no idea how to achieve this with PHP. Requirements:
- The simplest solution as possible, ++ if you use only PHP extensions enabled by default.
- I don't need Windows support :)
PS: Don't tell me to use nodejs or [your-favorite-language]
that doesn't suck :)