start listen for incoming connections

@param int $backlog maximum number of incoming connections to be queued
@return self $this (chainable)
@throws Exception on error
@see self::bind() has to be called first to bind name to socket
@uses socket_listen()
170754
public function listen($backlog = 0)
    {
        $ret = @socket_listen($this->resource, $backlog);
        if ($ret === false) {
            throw Exception::createFromSocketResource($this->resource);
        }
        return $this;
    }
486652
public function listen(): void
    {
        $this->socket = stream_socket_server(
            $this->getUri(),
            $errno,
            $errstr,
            STREAM_SERVER_BIND | STREAM_SERVER_LISTEN,
            $this->getStreamContext()
        );

        if (!$this->socket) {
            throw new ConnectionException(sprintf(
                'Could not listen on socket: %s (%d)',
                $errstr,
                $errno
            ));
        }

        $this->listening = true;
    }
972507
public function listenOn(ZMQConnection $connection) : self
    {
        $connection->subscribe([$this->topic], function ($message) {
            return $this->onSuccess($message);
        });

        return $this;
    }
848589
public function start($arguments)
    {
        if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $this->sockets) === false) {
            throw  new \Exception(socket_strerror(socket_last_error()));
        }

        $pid = @pcntl_fork();
        if ($pid == -1) {
            $this->fatalError(Thread::COULD_NOT_FORK);
        }
        if ($pid) {
            // parent

            $this->_pid = $pid;
        } else {
            // child
            pcntl_signal(SIGTERM, array($this, 'handleSignal'));

            if (!empty($arguments)) {
                $results = call_user_func_array($this->runnable, $arguments);
            } else {
                $results = call_user_func($this->runnable);
            }

            $data = serialize($results);
            socket_write($this->sockets[0], str_pad($data, $this->message_length), $this->message_length);
            socket_close($this->sockets[0]);

            exit(0);
        }
    }
62646
private function connect()
  {
    if ($this->connection) {
      return;
    }

    if (class_exists("Memcached")) {
      $this->mc = new Memcached();
      $this->mc->addServer($this->host, $this->port);
       $this->connection = true;
    } else {
      $this->connection = memcache_pconnect($this->host, $this->port);
    }

    if (! $this->connection) {
      $error = "Couldn't connect to memcache server";

      $this->client->getLogger()->error($error);
      throw new Google_Cache_Exception($error);
    }
  }
514260
public function handleConnection($socket)
    {
        stream_set_blocking($socket, 0);
        $client = $this->createConnection($socket);

        $timer = $this->loop->addTimer(5, function() use ($client) {
            $client->removeAllListeners('init');
            $client->end('Timeout waiting for PROXY header.');
            $this->emit('proxytimeout', [new Connection($client->stream, $this->loop)]);
        });

        $client->on('init', function($connection) use ($client, $timer) {
            $timer->cancel();
            $this->emit('connection', [$connection]);
        });
    }
229077
public function listen() 
    {        
        $context = stream_context_create(['socket' => $this->options]);        
        if($this->getOption('SO_REUSEPORT')) {
            stream_context_set_option($context, 'socket', 'so_reuseport', 1);
        }
        
        $flag = $this->isUDP() ? STREAM_SERVER_BIND : STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
        
        if($this->is_ssl ){
            foreach($this->ssl as $name => $value){
                if($value === null) continue;
                stream_context_set_option($context, 'ssl', $name, $value);
            }
        }
        
        $errno = $errmsg = null;
        
        $this->socket = @stream_socket_server($this->socket_name, $errno, $errmsg, $flag, $context);
        if(!$this->socket || $errno) {
            $this->socket = null;
            Yii::error("$this->listen $errmsg");
            return false;
        }
        
        /**
        When you create the binding for stream_socket_server(), make sure that you choose the tcp:// wrapper. 
        DO NOT USE ssl:// or tls://. Anything other than tcp:// will not work correctly AS A SERVER, 
        those transports are what you use when making connections with PHP as a client.
         
        Remember that the encryption does not start until after an SSL handshake completed, 
        so the server has to listen in non-encrypted mode for new connections, 
        and encryption doesn't start until certs are exchanged and a cipher is selected. 
        When a new connection arrives you accept it with stream_socket_accept() and then use stream_socket_enable_crypto() to start the SSL session.        
         */
        
        if($this->is_ssl){
            stream_socket_enable_crypto($this->socket, false);            
        }
        
        if($this->isUnix()){
            list(,$sockfile) = explode('://', $this->socket_name, 2);
            $sockfile = realpath($sockfile);
            $this->socket_name = $this->transport.'://'.$sockfile;
            chmod($sockfile, 0777);
        }
        
        if (function_exists('socket_import_stream') && $this->transport === 'tcp' ) {
            $socket = socket_import_stream($this->socket);
            foreach($this->options as $name => $value) {
                if($value === null || !defined($name)) continue;
                socket_set_option($socket, SOL_SOCKET, constant($name), $value);
            }
           
            socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1);
        }
        
        stream_set_blocking($this->socket, 0);
        
        stream_socket_enable_crypto($this->socket, false);
        
        Yii::debug("$this->listen listened", 'beyod');
        
        return $this;
    }
344653
public function start()
    {
        if ($this->restart) {
            echo 'Restarting consumer.' . PHP_EOL;
            $this->restart = false;
        } else {
            echo 'Starting consumer.' . PHP_EOL;
        }

        $exchange = 'router';
        $queue    = 'msgs';

        $this->channel = $this->connection->channel();
        $this->channel->queue_declare($queue, false, true, false, false);
        $this->channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, false, true, false);
        $this->channel->queue_bind($queue, $exchange);
        $this->channel->basic_consume(
            $queue,
            $this->consumerTag,
            false,
            false,
            false,
            false,
            [$this,'messageHandler'],
            null,
            ['x-cancel-on-ha-failover' => ['t', true]] // fail over to another node
        );

        echo 'Enter wait.' . PHP_EOL;
        while ($this->channel->is_consuming()) {
            $this->channel->wait();
        }
        echo 'Exit wait.' . PHP_EOL;
    }
122711
public void bind(Handler<AsyncResult<Void>> completion) {
        logger.info("Starting server {}", name);
        context = vertx.getOrCreateContext();
        bind(port, completion);
    }
500100
function listen(self, address, port, addressType, backlog, exclusive) {
    /* TODO Index servers by a self-assigned identifier and the process
     * identifier so messages intended for previous instances do not pass
     * through. */
    servers[port] = self; // Index servers by port.
    self._port = port; // Remember the requested port for close.
    process.send({
        cmd: 'CLUSTER_LISTEN',
        port: port,
        address: address, // For confirmation purposes only.
        addressType: addressType, // We allow the supervisor to infer the address type.
        backlog: backlog, // Used to confirm uniformity of worker requests.
        exclusive: exclusive // TODO use this on the other end
    });
}
229304
protected function __bindEvents()
    {
        $server = $this->swoolePort ?? $this->swooleServer;

        $server->on('packet', function(\swoole_server $server, $data, $clientInfo){
            try{
                $this->trigger('packet', [
                    'server'        => $this,
                    'data'          => $data,
                    'clientInfo'    => $clientInfo,
                ], $this, PacketEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });
        
    }
307108
public function startHAR($logName = 'default')
    {
        $this->requireOpenConnection();

        $response = $this->curl(
            'PUT',
            '/proxy/' . $this->port . '/har',
            array('initialPageRef' => $logName)
        );
    }
1168516
protected function __bindEvents()
    {
        $server = $this->swoolePort ?? $this->swooleServer;

        $server->on('connect', function(\swoole_server $server, $fd, $reactorID){
            try{
                $this->trigger('connect', [
                    'server'    => $this,
                    'fd'        => $fd,
                    'reactorID' => $reactorID,
                ], $this, ConnectEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });
        
        $server->on('receive', function(\swoole_server $server, $fd, $reactorID, $data){
            try{
                $this->trigger('receive', [
                    'server'    => $this,
                    'fd'        => $fd,
                    'reactorID' => $reactorID,
                    'data'      => $data,
                ], $this, ReceiveEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });
        
        $server->on('close', function(\swoole_server $server, $fd, $reactorID){
            try{
                $this->trigger('close', [
                    'server'    => $this,
                    'fd'        => $fd,
                    'reactorID' => $reactorID,
                ], $this, CloseEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });

        $server->on('BufferFull', function(\swoole_server $server, $fd){
            try{
                $this->trigger('bufferFull', [
                    'server'    => $this,
                    'fd'        => $fd,
                ], $this, BufferEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });

        $server->on('BufferEmpty', function(\swoole_server $server, $fd){
            try{
                $this->trigger('bufferEmpty', [
                    'server'    => $this,
                    'fd'        => $fd,
                ], $this, BufferEventParam::class);
            }
            catch(\Throwable $ex)
            {
                App::getBean('ErrorLog')->onException($ex);
            }
        });
    }
371097
public function begin() {
        if($this->isInTransaction()) {
            throw new \Exception('You cannot start a new transaction once you are already in one (Originally started at: ' . self::$stackTrace . ')');
        } else {
            $e = new \Exception();
            self::$stackTrace = $e->getTraceAsString();
        }
        $transactionManager = new TransactionManager();
        $transactionManager->setDbService($this->getDbService());
        $this->setTransaction($transactionManager->get());
    }
193662
public void start() throws Exception
    {
        Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");

        client.getConnectionStateListenable().addListener(connectionStateListener);
        try
        {
            client.create().creatingParentContainersIfNeeded().forPath(path, seedValue);
        }
        catch ( KeeperException.NodeExistsException ignore )
        {
            // ignore
        }

        readValue();
    }
326614
def forwarder(frontend, backend):
    
    try:
        context = zmq.Context()

        front_sub = context.socket(zmq.SUB)
        front_sub.bind("tcp://*:%d" % frontend)

        front_sub.setsockopt_string(zmq.SUBSCRIBE, "")

        back_pub = context.socket(zmq.PUB)
        back_pub.bind("tcp://*:%d" % backend)

        print("forwarder started, backend on port : %d\tfrontend on port: %d" % (backend, frontend))
        zmq.proxy(front_sub, back_pub)
    except Exception as e:
        print(e)
    finally:
        front_sub.close()
        back_pub.close()
        context.term()
225666
public function addBackend(Backend\BackendInterface $backend)
    {
        if ($this->psrCompatibleLoggerWasInjected) {
            throw new Exception('A PSR-3 logger was injected so adding backends is not possible. Create a new instance.', 1515343013004);
        }

        $this->backends->attach($backend);
    }