Exemple #1
0
 /**
  * @covers React\Socket\Connection::end
  */
 public function testEnd()
 {
     $socket = fopen('php://temp', 'r+');
     $loop = $this->createLoopMock();
     $conn = new Connection($socket, $loop);
     $conn->end();
     $this->assertFalse(is_resource($socket));
 }
Exemple #2
0
 public function onWeb(\React\Socket\Connection $incoming)
 {
     $slaveId = $this->getNextSlave();
     $port = $this->slaves[$slaveId]['port'];
     $client = stream_socket_client('tcp://127.0.0.1:' . $port);
     $redirect = new \React\Stream\Stream($client, $this->loop);
     $redirect->on('close', function () use($incoming) {
         $incoming->end();
     });
     $incoming->on('data', function ($data) use($redirect) {
         $redirect->write($data);
     });
     $redirect->on('data', function ($data) use($incoming) {
         $incoming->write($data);
     });
 }
Exemple #3
0
 /**
  * A slave sent a `status` command.
  *
  * @param array $data
  * @param Connection $conn
  */
 protected function commandStatus(array $data, Connection $conn)
 {
     $conn->end(json_encode('todo'));
 }
Exemple #4
0
 /**
  * A slave sent a `status` command.
  *
  * @param array      $data
  * @param Connection $conn
  */
 protected function commandStatus(array $data, Connection $conn)
 {
     //remove nasty info about worker's bootstrap fail
     $conn->removeAllListeners('close');
     if ($this->output->isVeryVerbose()) {
         $conn->on('close', function () {
             $this->output->writeln('Status command requested');
         });
     }
     $conn->end(json_encode(['slaveCount' => $this->slaveCount, 'handledRequests' => $this->handledRequests]));
 }
 /**
  * Override the base end to add encryption if we're in an encypted stage
  *
  * @param $data String the data to write on ending
  * @Override
  */
 public function end($data = null)
 {
     //encrypt the data if needed
     if ($data !== null && $this->secret !== null) {
         mcrypt_generic_init($this->encryptor, $this->secret, $this->secret);
         $data = mcrypt_generic($this->encryptor, $data);
         mcrypt_generic_deinit($this->encryptor);
     }
     parent::end($data);
 }
 protected function serve404Error(SocketConnection $conn)
 {
     $response = new Response('file not found.', Response::HTTP_NOT_FOUND);
     $conn->write($response);
     $conn->end();
 }