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); |