Clue\React\Buzz\Io\UnixConnector::create PHP Method

create() public method

public create ( $host, $port )
    public function create($host, $port)
    {
        $deferred = new Deferred();
        $resource = @stream_socket_client($this->path, $errno, $errstr, 1.0);
        if (!$resource) {
            $deferred->reject(new RuntimeException('Unable to connect to unix domain socket path: ' . $errstr, $errno));
        } else {
            $deferred->resolve(new Stream($resource, $this->loop));
        }
        return $deferred->promise();
    }

Usage Example

Example #1
0
 public function testValid()
 {
     $path = tempnam(sys_get_temp_dir(), 'socket');
     $server = @stream_socket_server('unix://' . $path, $errno, $errstr);
     if (!$server) {
         $this->markTestSkipped('Unable to create socket: ' . $errstr . '(' . $errno . ')');
         return;
     }
     $loop = $this->getMock('React\\EventLoop\\LoopInterface');
     $connector = new UnixConnector($loop, 'unix://' . $path);
     $promise = $connector->create('localhost', 80);
     $stream = Block\await($promise, $loop);
     /* @var $stream React\Stream\Stream */
     $stream->close();
     fclose($server);
     unlink($path);
 }