react/child-process

(要求Workerman版本>=3.3.6)

安装:

  1. composer require react/child-process

示例:

  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3. use Workerman\Worker;
  4. $worker = new Worker('tcp://127.0.0.1:1234');
  5. $worker->onWorkerStart = function() {
  6. $loop = Worker::getEventLoop();
  7. $process = new React\ChildProcess\Process('echo hello');
  8. $process->start($loop);
  9. $process->on('exit', function($exitCode, $termSignal) {
  10. echo "cmd complete\n";
  11. });
  12. $process->stdout->on('data', function($output) {
  13. echo $output;
  14. });
  15. $process->stderr->on('data', function($output) {
  16. echo $output;
  17. });
  18. };
  19. Worker::runAll();

文档:

https://github.com/reactphp/child-process

注意:

1、所有的异步编码必须在onXXX回调中编写

2、异步客户端需要的$loop变量请使用Worker::getEventLoop();返回值