8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
20 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Http_Client_Adapter_Socket
27 require_once 'Zend/Http/Client/Adapter/Socket.php';
30 * Overrides the traditional socket-based adapter class for Zend_Http_Client to
31 * enable logging of requests. All requests are logged to a location specified
32 * in the config as $config['logfile']. Requests and responses are logged after
33 * they are sent and received/processed, thus an error could prevent logging.
38 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39 * @license http://framework.zend.com/license/new-bsd New BSD License
41 class Zend_Gdata_App_LoggingHttpClientAdapterSocket extends Zend_Http_Client_Adapter_Socket
45 * The file handle for writing logs
49 protected $log_handle = null;
52 * Log the given message to the log file. The log file is configured
53 * as the config param 'logfile'. This method opens the file for
54 * writing if necessary.
56 * @param string $message The message to log
58 protected function log($message)
60 if ($this->log_handle == null) {
61 $this->log_handle = fopen($this->config['logfile'], 'a');
63 fwrite($this->log_handle, $message);
67 * Connect to the remote server
71 * @param boolean $secure
74 public function connect($host, $port = 80, $secure = false)
76 $this->log("Connecting to: ${host}:${port}");
77 return parent::connect($host, $port, $secure);
81 * Send request to the remote server
83 * @param string $method
84 * @param Zend_Uri_Http $uri
85 * @param string $http_ver
86 * @param array $headers
88 * @return string Request as string
90 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
92 $request = parent::write($method, $uri, $http_ver, $headers, $body);
93 $this->log("\n\n" . $request);
98 * Read response from server
102 public function read()
104 $response = parent::read();
105 $this->log("${response}\n\n");
110 * Close the connection to the server
113 public function close()
115 $this->log("Closing socket\n\n");