/** * @param int $domain * @param int $type * @param int $protocol * @return Socket * @throws Exception */ public function create($domain, $type, $protocol) { $sock = @socket_create($domain, $type, $protocol); if ($sock === false) { throw Exception::createFromGlobalSocketOperation('Unable to create socket'); } return new Socket($sock); }
/** * create TCP/IPv4 stream socket and listen for new connections * * @param int $port * @param int $backlog * @return \Socket\Raw\Socket * @throws Exception if creating listening socket fails * @uses socket_create_listen() * @see self::createServer() as an alternative to bind to specific IP, IPv6, UDP, UNIX, UGP */ public function createListen($port, $backlog = 128) { $sock = @socket_create_listen($port, $backlog); if ($sock === false) { throw Exception::createFromGlobalSocketOperation('Unable to create listening socket'); } return new Socket($sock); }