Get a socket from the list to reuse, if any are available

@codeCoverageIgnore

@return \GameQ\Query\Core|null
508830
public function socketGet()
    {

        $socket = null;

        if (count($this->sockets) > 0) {
            $socket = array_pop($this->sockets);
        }

        return $socket;
    }
1324051
public function disconnect()
    {
        $streamResource = $this->getStreamResource();

        if (is_resource($streamResource)) {
            stream_socket_shutdown($streamResource, STREAM_SHUT_RDWR);
            $this->streamResource = null;
        }

        return $this;
    }
304011
public static function getInstanceAndConnect() {
		if (!is_object(self::getInstance())) {
			return NULL;
		}
		if (!self::$instance->tryConnect()) {
			return NULL;
		}
		return self::$instance;
	}
1264359
function get()
    {
        $result = $this->client->get($this->requestDecorator->makeResource(), $this->requestDecorator->makeQuery());
        $this->refresh();
        return $result;
    }
1135695
public function chosen() : ?Connection
    {
        if ($this->helperSet->has($this->helperName)) {
            $connectionHelper = $this->helperSet->get($this->helperName);

            if ($connectionHelper instanceof ConnectionHelper) {
                return $connectionHelper->getConnection();
            }
        }

        return null;
    }
1271206
private function getSQL() {
        try {
            $this->checkDialect();
        } catch (DialectException $e) {
            return null;
        }
        if (!$this->values) {
            $this->values = new BindValues ();
        } else if (!$this->valueFixed) {
            $this->values->reset();
        }
        $fields = $this->prepareFields($this->fields, $this->values);
        $from   = $this->prepareFrom($this->sanitize($this->from));
        $joins  = $this->prepareJoins($this->sanitize($this->joins));
        $having = $this->sanitize($this->having);
        $group  = $this->sanitize($this->group);
        $order  = $this->sanitize($this->order);

        return $this->dialect->getSelectSQL($fields, $from, $joins, $this->where, $having, $group, $order, $this->limit, $this->values, $this->forupdate);
    }
433347
private function getSock()
    {
        // Try connecting
        if (!($sock = @fsockopen($this->host, $this->port, $errno, $errstr, self::timeout))) {
            throw new Exception('Error connecting');
        }

        // Try getting stuff
        $buffer = '';
        while ($mid = @fgets($sock)) {
            $buffer .= $mid;
        }

        // Quit
        @fclose($sock);

        // Output:
        return $buffer;
    }
655383
public function getConnection()
    {
        if (null === $this->connection) {
            $this->setConnection(\Doctrine_Manager::getInstance()->getCurrentConnection());
        }

        return $this->connection;
    }
681630
public function getConnection():ConnectionInterface
    {
        if (App::isCoContext()) {
            $connection = $this->getConnectionByChannel();
        } else {
            $connection = $this->getConnectionByQueue();
        }

        if ($connection->check() == false) {
            $connection->reconnect();
        }

        $this->addContextConnection($connection);
        return $connection;
    }
1228979
private function getDelivery()
    {
        $returnValue = null;
        //passed as aprameter
        if ($this->hasRequestParameter('delivery')) {
            $returnValue = new core_kernel_classes_Resource($this->getRequestParameter('delivery'));
        } else {
            
            $launchData = LtiService::singleton()->getLtiSession()->getLaunchData();

            /** @var LtiLaunchDataService $launchDataService */
            $launchDataService = $this->getServiceLocator()->get(LtiLaunchDataService::SERVICE_ID);
            $returnValue = $launchDataService->findDeliveryFromLaunchData($launchData);
        }
        return $returnValue;
    }
20374
protected function connectZmq()
    {
        $context = new ZMQContext();
        $this->socket = $context->getSocket(ZMQ::SOCKET_PUSH, self::SOCKET_PULL_ID . '.' . App::environment());
        $this->socket->connect('tcp://localhost:' . config('twostream.push.port'));
        
        return $this->socket;
    }
385171
public function socket($request = null)
    {
        if (! $request && ! $this->container->bound('request')) {
            return null;
        }

        $request = $request ?: $this->container['request'];

        return $request->header('X-Socket-ID');
    }
252309
protected function getSocket($server)
    {
        if (isset($this->socket[$server])) {
            return $this->socket[$server];
        }

        $context = new ZMQContext();
        $socket = Socket::create($context, ZMQ::SOCKET_REQ, $this->logger);
        $socket->connect($server);

        $this->socket[$server] = $socket;

        return $socket;
    }
1217266
public function disconnect()
    {
        if (!$this->socket) {
            return $this;
        }

        try {
            $this->send('QUIT');
        } catch (\Exception $e) {
            // ignore error - we're closing the socket anyway
        }

        fclose($this->socket);
        $this->socket = null;

        return $this;
    }
1270787
public function getServer() {
        $server = 'mongodb://';

        if ($servers = $this->getConfig('servers')) {
            $server .= implode(',', $servers);

        } else {
            if ($socket = $this->getSocket()) {
                $server .= $socket;
            } else {
                $server .= $this->getHost() . ':' . $this->getPort();
            }
        }

        return $server;
    }
115645
public function query()
    {
        // check if the host is in ipv4 format
        $host = filter_var($this->host, FILTER_VALIDATE_IP) ? $this->host : gethostbyname($this->host);
        
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 1, 'usec' => 0));
        socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1, 'usec' => 0));

        if (!@socket_connect($socket, $host, $this->port)) {
            return false;
        }
        
        // create the handshake and ping packet
        $handshakePacket = new HandshakePacket($host, $this->port, 107, 1);
        $pingPacket = new PingPacket();

        $handshakePacket->send($socket);

        // high five
        $start = microtime(true);
        $pingPacket->send($socket);
        $length = $this->readVarInt($socket);
        $ping = round((microtime(true) - $start) * 1000);

        // read the requested data
        $data = socket_read($socket, $length, PHP_NORMAL_READ);
        $data = strstr($data, '{');
        $data = json_decode($data);

        $descriptionRaw = isset($data->description) ? $data->description : null;
        $description = $descriptionRaw;

        // colorize the description if it is supported
        if (gettype($descriptionRaw) == 'object') {
            $description = '';

            if (isset($descriptionRaw->text)) {
                $color = isset($descriptionRaw->color) ? $descriptionRaw->color : null;
                $description = $descriptionRaw->text;
                if ($color !== null) {
                    $description = '<font color="' . $color . '">' . $descriptionRaw->text . '</font>';
                }
            }

            if (isset($descriptionRaw->extra)) {
                foreach ($descriptionRaw->extra as $item) {
                    $description .= isset($item->bold) && $item->bold ? '<b>' : null;
                    $description .= isset($item->color) ? '<font color="' . $item->color . '">' . $item->text . '</font>' : $item->text;
                    $description .= isset($item->bold) && $item->bold ? '</b>' : null;
                }
            }
        }

        $this->data
            ->setHostname($host)
            ->setPort($this->port)
            ->setPing($ping)
            ->setVersion(isset($data->version->name) ? $data->version->name : null)
            ->setProtocol(isset($data->version->protocol) ? $data->version->protocol : null)
            ->setPlayers(isset($data->players->online) ? $data->players->online : null)
            ->setMaxPlayers(isset($data->players->max) ? $data->players->max : null)
            ->setDescription($description)
            ->setDescriptionRaw($descriptionRaw)
            ->setFavicon(isset($data->favicon) ? $data->favicon : null)
            ->setModinfo(isset($data->modinfo) ? $data->modinfo : null)
        ;

        return true;
    }
239919
public function getConnection()
    {
        if(!$this->_connection) {
            $this->_connection = new \Guzzle\Http\Client($this->getHost());
        }

        return $this->_connection;
    }