Lines Matching refs:socket

254         $socket = null;
257 $socket = self::$connections[$connectionId];
259 if (is_null($socket) || feof($socket)) {
261 // open socket
262 $socket = @fsockopen($server,$port,$errno, $errstr, $this->timeout);
263 if (!$socket){
271 if($this->ssltunnel($socket, $request_url)){
280 fclose($socket);
286 self::$connections[$connectionId] = $socket;
303 stream_set_blocking($socket, 0);
313 $this->sendData($socket, $request, 'request');
315 // read headers from socket
318 $r_line = $this->readLine($socket, 'headers');
368 fclose($socket);
411 while (preg_match('/^[a-zA-Z0-9]?$/',$byte=$this->readData($socket,1,'chunk'))){
417 $this->readLine($socket, 'chunk'); // readtrailing \n
429 $r_body .= $this->readData($socket, $chunk_size, 'chunk');
430 $this->readData($socket, 2, 'chunk'); // read trailing \r\n
440 // for keep alive we need to read the whole message to clean up the socket for the next read
451 $r_body = $this->readData($socket, $length, 'response (content-length limited)', true);
453 $r_body = $this->readData($socket, $this->max_bodysize+1, 'response (content-length limited)', true);
457 // read entire socket
458 while (!feof($socket)) {
459 $r_body .= $this->readData($socket, 4096, 'response (unlimited)', true);
479 fclose($socket);
485 // close socket
486 fclose($socket);
513 * @param resource &$socket
518 protected function ssltunnel(&$socket, &$requesturl){
533 $this->sendData($socket, $request, 'SSL Tunnel CONNECT');
535 // read headers from socket
538 $r_line = $this->readLine($socket, 'headers');
545 stream_context_set_option($socket, 'ssl', 'peer_name', $requestinfo['host']);
556 if (@stream_socket_enable_crypto($socket, true, $cryptoMethod)) {
571 * Safely write data to a socket
573 * @param resource $socket An open socket handle
580 protected function sendData($socket, $data, $message) {
589 if(feof($socket))
594 $sel_w = array($socket);
603 $nbytes = fwrite($socket, substr($data,$written,4096));
605 throw new HTTPClientException("Failed writing to socket while sending $message", -100);
611 * Safely read data from a socket
616 * @param resource $socket An open socket handle in non-blocking mode
625 protected function readData($socket, $nbytes, $message, $ignore_eof = false) {
636 if(feof($socket)) {
638 throw new HTTPClientException("Premature End of File (socket) while reading $message");
644 $sel_r = array($socket);
653 $bytes = fread($socket, $to_read);
655 throw new HTTPClientException("Failed reading from socket while reading $message", -100);
664 * Safely read a \n-terminated line from a socket
668 * @param resource $socket An open socket handle in non-blocking mode
675 protected function readLine($socket, $message) {
683 if(feof($socket))
684 throw new HTTPClientException("Premature End of File (socket) while reading $message");
687 $sel_r = array($socket);
696 $r_data = fgets($socket, 1024);