Lines Matching refs:socket

249         $socket = null;
252 $socket = self::$connections[$connectionId];
254 if (is_null($socket) || feof($socket)) {
256 // open socket
257 $socket = @fsockopen($server, $port, $errno, $errstr, $this->timeout);
258 if (!$socket) {
266 if ($this->ssltunnel($socket, $request_url)) {
275 fclose($socket);
281 self::$connections[$connectionId] = $socket;
298 stream_set_blocking($socket, 0);
308 $this->sendData($socket, $request, 'request');
310 // read headers from socket
313 $r_line = $this->readLine($socket, 'headers');
362 fclose($socket);
405 while (preg_match('/^[a-zA-Z0-9]?$/', $byte = $this->readData($socket, 1, 'chunk'))) {
411 $this->readLine($socket, 'chunk'); // readtrailing \n
423 $r_body .= $this->readData($socket, $chunk_size, 'chunk');
424 $this->readData($socket, 2, 'chunk'); // read trailing \r\n
437 // for keep alive we need to read the whole message to clean up the socket for the next read
448 $r_body = $this->readData($socket, $length, 'response (content-length limited)', true);
450 $r_body = $this->readData($socket, $this->max_bodysize + 1, 'response (content-length limited)', true);
454 // read entire socket
455 while (!feof($socket)) {
456 $r_body .= $this->readData($socket, 4096, 'response (unlimited)', true);
475 fclose($socket);
483 // close socket
484 fclose($socket);
513 * @param resource &$socket
518 protected function ssltunnel(&$socket, &$requesturl)
535 $this->sendData($socket, $request, 'SSL Tunnel CONNECT');
537 // read headers from socket
540 $r_line = $this->readLine($socket, 'headers');
547 stream_context_set_option($socket, 'ssl', 'peer_name', $requestinfo['host']);
558 if (@stream_socket_enable_crypto($socket, true, $cryptoMethod)) {
574 * Safely write data to a socket
576 * @param resource $socket An open socket handle
583 protected function sendData($socket, $data, $message)
593 if (feof($socket))
598 $sel_w = [$socket];
607 $nbytes = fwrite($socket, substr($data, $written, 4096));
609 throw new HTTPClientException("Failed writing to socket while sending $message", -100);
615 * Safely read data from a socket
620 * @param resource $socket An open socket handle in non-blocking mode
629 protected function readData($socket, $nbytes, $message, $ignore_eof = false)
647 if (feof($socket)) {
649 throw new HTTPClientException("Premature End of File (socket) while reading $message");
655 $sel_r = [$socket];
664 $bytes = fread($socket, $to_read);
666 throw new HTTPClientException("Failed reading from socket while reading $message", -100);
675 * Safely read a \n-terminated line from a socket
679 * @param resource $socket An open socket handle in non-blocking mode
686 protected function readLine($socket, $message)
696 if (feof($socket))
697 throw new HTTPClientException("Premature End of File (socket) while reading $message");
700 $sel_r = [$socket];
709 $r_data = fgets($socket, 1024);