Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • Connector
  • DnsConnector
  • LimitingServer
  • SecureConnector
  • SecureServer
  • Server
  • TcpConnector
  • TimeoutConnector
  • UnixConnector

Interfaces

  • ConnectionInterface
  • ConnectorInterface
  • ServerInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace React\Socket;
 4: 
 5: use React\Socket\ConnectorInterface;
 6: use React\EventLoop\LoopInterface;
 7: use React\Promise;
 8: use RuntimeException;
 9: 
10: /**
11:  * Unix domain socket connector
12:  *
13:  * Unix domain sockets use atomic operations, so we can as well emulate
14:  * async behavior.
15:  */
16: final class UnixConnector implements ConnectorInterface
17: {
18:     private $loop;
19: 
20:     public function __construct(LoopInterface $loop)
21:     {
22:         $this->loop = $loop;
23:     }
24: 
25:     public function connect($path)
26:     {
27:         if (strpos($path, '://') === false) {
28:             $path = 'unix://' . $path;
29:         } elseif (substr($path, 0, 7) !== 'unix://') {
30:             return Promise\reject(new \InvalidArgumentException('Given URI "' . $path . '" is invalid'));
31:         }
32: 
33:         $resource = @stream_socket_client($path, $errno, $errstr, 1.0);
34: 
35:         if (!$resource) {
36:             return Promise\reject(new RuntimeException('Unable to connect to unix domain socket "' . $path . '": ' . $errstr, $errno));
37:         }
38: 
39:         return Promise\resolve(new Connection($resource, $this->loop));
40:     }
41: }
42: 
Ratchet API documentation generated by ApiGen 2.8.0