I need a parallel task runner in PHP (most likely on windows - IIS7 fastcgi), which has a complete implementation hiding. Its interface should be something like this:
$taskRunner = new ParallelTaskRunner();
$taskRunner->add(function () use ($sharedResource){
//task 1
});
$taskRunner->add(function () use ($sharedResource){
//task 2
});
$taskRunner->run(); //runs task 1, task 2 parallel
I have done some research: I am aware of techniques with which I can run PHP code parallel - pthreads, pcntl, exec, gearman, curl multi, etc...
The questions I need answer for:
- Is it possible to make this implementation hiding with any of these techniques? How is it possible to do that (if there is some advanced workaround in implementation details)? Is there any library which has this feature?
- How can I extract the information about the running of the parallel tasks? For example:
task1: { a(); b(); }
,task2: { c(); }
, how can I know that the calling order of the functions wasa(); b(); c();
ora(); c(); b();
orc(); a(); b();
? - How can I debug my tasks if something goes wrong?
update
I checked many possible solution, and I ended up with pthreads. It is much easier to use threads than processes... The only drawback that it does not support xdebug.