christiaan/stream-process

Wrapper around proc_open to ease communication via streams between processes

Installs: 310

Dependents: 1

Stars: 1

Watchers: 1

Language: PHP

1.0.1 2013-03-27 10:04 UTC

README

Build Status

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.