phasty / process
PHP for asynchronous task execution
Installs: 7 442
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- phasty/events: 0.1.*
- phasty/log: 0.1.*
- phasty/stream: 0.2.*
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-10-26 17:13:29 UTC
README
Allows you make any job in another php-process with ability to get feedback from child process during all execution time:
// Child process code:
use Phasty\process\Child\CallableClass;
class ChildProcess extends CallableClass {
public $property = "A";
public function doAsyncJob($arg1, $arg2) {
$this->trigger("doneJob", (object)[ "result" => $arg1 . $arg2 . $this->property ]);
}
}
And parent process code:
use Phasty\Stream\StreamSet;
use Phasty\Process\Child\Controller;
$process = new Controller(ChildProcess::getClass());
/*
or you can use instance of class ChildProcess with predefined state like this:
$childJob = new ChildProcess;
$childJob->property = "B";
$process = new Controller($childJob);
*/
$process->on("start", function () {
echo "Child process started\n";
});
$process->on("stop", function () {
echo "Child process stopped\n";
});
$process->on("doneJob", function ($event) {
echo "Got result from child: " . $event->getData()->result . "\n";
});
$process->doAsyncJob("foo", "bar");
StreamSet::instance()->listen();
echo "stopped\n";
After execution you should see:
Child process started
Got result from child: foobarA
Child process stopped
stopped
You can receive event "error" in parent process on child object in case of catchable error occured or signal (including SIGTERM, SIGFAULT etc)
Coming soon:
1. Killing process with $process->kill();
2. Getting result code
- Bi-directional link (sending commands to child)
4. Getting stop reason (normal, signals like segmentation fault and so on)