includes/http.php
changeset 349 fdaf9070566c
parent 328 dc838fd61a06
child 354 979d99a0b00e
equal deleted inserted replaced
348:87e08a6e4fec 349:fdaf9070566c
   322    * @access private
   322    * @access private
   323    */
   323    */
   324   
   324   
   325   function _sock_open(&$connection)
   325   function _sock_open(&$connection)
   326   {
   326   {
       
   327     // Open connection
       
   328     $connection = fsockopen($this->host, $this->port);
       
   329     if ( !$connection )
       
   330       die(__CLASS__ . '::' . __METHOD__ . ': Could not make connection');
       
   331     
       
   332     // 1 = socket open
       
   333     $this->state = 1;
       
   334   }
       
   335   
       
   336   /**
       
   337    * Internal function to actually write the request into the socket.
       
   338    * @access private
       
   339    */
       
   340   
       
   341   function _write_request(&$connection, &$headers, &$cookies, &$get, &$post)
       
   342   {
       
   343     $newline = "\r\n";
       
   344     
       
   345     if ( $this->debug )
       
   346       echo '<p>Connection opened. Writing main request to socket. Raw socket data follows.</p><pre>';
       
   347     
   327     if ( $this->debug )
   348     if ( $this->debug )
   328     {
   349     {
   329       echo '<hr /><div style="white-space: nowrap;">';
   350       echo '<hr /><div style="white-space: nowrap;">';
   330       echo '<p><b>' . __CLASS__ . ': Sending request</b></p><p>Request parameters:</p>';
   351       echo '<p><b>' . __CLASS__ . ': Sending request</b></p><p>Request parameters:</p>';
   331       echo "<p><b>Headers:</b></p><pre>$headers</pre>";
   352       echo "<p><b>Headers:</b></p><pre>$headers</pre>";
   332       echo "<p><b>Cookies:</b> $cookies</p>";
   353       echo "<p><b>Cookies:</b> $cookies</p>";
   333       echo "<p><b>GET URI:</b> " . htmlspecialchars($get) . "</p>";
   354       echo "<p><b>GET URI:</b> " . htmlspecialchars($this->uri . $get) . "</p>";
   334       echo "<p><b>POST DATA:</b> " . htmlspecialchars($post) . "</p>";
   355       echo "<p><b>POST DATA:</b> " . htmlspecialchars($post) . "</p>";
   335     }
   356     }
   336     
   357     echo "<pre>";
   337     // Open connection
       
   338     $connection = fsockopen($this->host, $this->port);
       
   339     if ( !$connection )
       
   340       die(__CLASS__ . '::' . __METHOD__ . ': Could not make connection');
       
   341     
       
   342     if ( $this->debug )
       
   343       echo '<p>Connection opened. Writing main request to socket. Raw socket data follows.</p><pre>';
       
   344     
       
   345     // 1 = socket open
       
   346     $this->state = 1;
       
   347   }
       
   348   
       
   349   /**
       
   350    * Internal function to actually write the request into the socket.
       
   351    * @access private
       
   352    */
       
   353   
       
   354   function _write_request(&$connection, &$headers, &$cookies, &$get, &$post)
       
   355   {
       
   356     $newline = "\r\n";
       
   357     
   358     
   358     $this->_fputs($connection, "{$this->method} {$this->uri}{$get} HTTP/1.1{$newline}");
   359     $this->_fputs($connection, "{$this->method} {$this->uri}{$get} HTTP/1.1{$newline}");
   359     $this->_fputs($connection, "Host: {$this->host}{$newline}");
   360     $this->_fputs($connection, "Host: {$this->host}{$newline}");
   360     $this->_fputs($connection, $headers);
   361     $this->_fputs($connection, $headers);
   361     $this->_fputs($connection, $cookies);
   362     $this->_fputs($connection, $cookies);
   391   function sock_close(&$connection)
   392   function sock_close(&$connection)
   392   {
   393   {
   393     if ( $this->debug )
   394     if ( $this->debug )
   394     {
   395     {
   395       echo '<p>Response fetched. Closing connection. Response text follows.</p><pre>';
   396       echo '<p>Response fetched. Closing connection. Response text follows.</p><pre>';
   396       echo htmlspecialchars($buffer);
   397       echo htmlspecialchars($this->response);
   397       echo '</pre></div><hr />';
   398       echo '</pre></div><hr />';
   398     }
   399     }
   399     
   400     
   400     fclose($connection);
   401     fclose($connection);
   401   }
   402   }