public function create($class, array $data = []) { $transport = $this->createUnixTransport(); $messenger = MessengerFactory::server($transport); $this->process = new Thread($transport, $class, $data); $this->process->start(PTHREADS_INHERIT_NONE); return $messenger; }
public function create($class, array $data = []) { $transport = $this->createUnixTransport(); $messenger = MessengerFactory::server($transport); $script = sprintf($this->script, EPROCESS_AUTOLOAD, $transport, $class, base64_encode($this->serialize($data))); $this->process = new PhpProcess($script); $this->process->start(); return $messenger; }
private function transport_works_simulatenously(LoopInterface $loop, TransportInterface $transport) { $server = MessengerFactory::server($transport); $client = MessengerFactory::client($transport); $this->assertInstanceOf(Messenger::class, $server); $this->assertInstanceOf(Messenger::class, $client); $tester = new Tester(); $tester->messages[] = new TestMessage('event1', 'args1'); $tester->messages[] = new TestMessage('event2', 'args123'); $tester->initialize($server, $client, $loop); }
public function create($class, array $data = []) { $executableFinder = new PhpExecutableFinder(); if (false === ($php = $executableFinder->find())) { throw new \RuntimeException('Unable to find the PHP executable.'); } $transport = $this->createUnixTransport(); $messenger = MessengerFactory::server($transport); $script = sprintf($this->script, EPROCESS_AUTOLOAD, $this->getUnixSocketAddress(), $class, base64_encode($this->serialize($data))); $this->process = new Process($php); $this->process->start($this->loop, 0.1); $this->process->stdin = new FullDrainStream($this->process->stdin->stream, $this->loop); $this->process->stdin->write($script); $this->process->stdin->on('full-drain', function () { $this->process->stdin->close(); }); $this->process->stdout->on('data', function ($data) { echo $data; }); $this->process->stderr->on('data', function ($data) { echo $data; }); return $messenger; }