christiaan / stream-process
Wrapper around proc_open to ease communication via streams between processes
Installs: 11 770
Dependents: 1
Suggesters: 1
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >= 5.3.2
Requires (Dev)
- mkraemer/react-pcntl: dev-master
- phpunit/phpunit: ^7.2
- react/event-loop: *
Suggests
- react/event-loop: Allows easier working with streams and waiting till data is available
This package is auto-updated.
Last update: 2024-11-06 15:40:42 UTC
README
Easily spawn processes and communicate with them using streams. Mainly build to be used together with react/event-loop.
Installation
composer.phar require christiaan/stream-process
Usage
$loop = \React\EventLoop\Factory::create(); $child = new StreamProcess('php someWorkerProcess.php'); $loop->addReadStream($child->getReadStream(), function($stream) { $data = fgets($stream); fwrite(STDOUT, $data); }); $loop->addPeriodicTimer(1, function() { pcntl_signal_dispatch(); }); pcntl_signal(SIGTERM, function() use($loop) { $loop->stop(); // Cleanup before closing exit(0); }); fwrite($child->getWriteStream(), 'start'); $loop->run();
Known issues
Not working on Windows because of this bug
Could possible be fixed by using files instead of direct streams.