/** * Retrieves a file from cache if it exists, otherwise retreive from net, * add to cache, and return from cache. * * @param string URL to WSDL * @param array proxy parameters * @param int expected MD5 of WSDL URL * @access public * @return string data */ function get($wsdl_fname, $proxy_params = array(), $cache = 0) { $cachename = $md5_wsdl = $file_data = ''; if ($this->_cacheUse) { // Try to retrieve WSDL from cache $cachename = SOAP_WSDL_Cache::_cacheDir() . '/' . md5($wsdl_fname) . ' .wsdl'; if (file_exists($cachename)) { $wf = fopen($cachename, 'rb'); if ($wf) { // Reading cached file $file_data = fread($wf, filesize($cachename)); $md5_wsdl = md5($file_data); fclose($wf); } if ($cache) { if ($cache != $md5_wsdl) { return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); } } else { $fi = stat($cachename); $cache_mtime = $fi[8]; //print cache_mtime, time() if ($cache_mtime + $this->_cacheMaxAge < time()) { // expired $md5_wsdl = ''; // refetch } } } } if (!$md5_wsdl) { // Not cached or not using cache. Retrieve WSDL from URL // is it a local file? // this section should be replace by curl at some point if (!preg_match('/^(https?|file):\\/\\//', $wsdl_fname)) { if (!file_exists($wsdl_fname)) { return $this->_raiseSoapFault("Unable to read local WSDL {$wsdl_fname}", $wsdl_fname); } if (function_exists('file_get_contents')) { $file_data = file_get_contents($wsdl_fname); } else { $file_data = implode('', file($wsdl_fname)); } } else { $uri = explode('?', $wsdl_fname); $rq =& new HTTP_Request($uri[0], $proxy_params); // the user agent HTTP_Request uses fouls things up if (isset($uri[1])) { $rq->addRawQueryString($uri[1]); } if (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port']) && isset($proxy_params['proxy_user']) && isset($proxy_params['proxy_pass'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], $proxy_params['proxy_user'], $proxy_params['proxy_pass']); } elseif (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']); } $result = $rq->sendRequest(); if (PEAR::isError($result)) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}," . $rq->getResponseCode(), $wsdl_fname); } $file_data = $rq->getResponseBody(); if (!$file_data) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}, no http body", $wsdl_fname); } } $md5_wsdl = md5($file_data); if ($this->_cacheUse) { $fp = fopen($cachename, "wb"); fwrite($fp, $file_data); fclose($fp); } } if ($this->_cacheUse && $cache && $cache != $md5_wsdl) { return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname); } return $file_data; }
/** * get * retreives file from cache if it exists, otherwise retreive from net, * add to cache, and return from cache */ function get($wsdl_fname, $cache = 0) { $cachename = SOAP_WSDL_Cache::_cacheDir() . "/" . md5($wsdl_fname); $cacheinfo = $cachename . ".info"; $cachename .= ".wsdl"; $md5_wsdl = ""; $file_data = ''; if (WSDL_CACHE_USE && file_exists($cachename)) { $wf = fopen($cachename, "rb"); if ($wf) { $file_data = fread($wf, filesize($cachename)); $md5_wsdl = md5($file_data); fclose($wf); } if ($cache) { if ($cache != $md5_wsdl) { return $this->raiseSoapFault("WSDL Checksum error!", $wsdl_fname); } } else { $fi = stat($cachename); $cache_mtime = $fi[8]; #print cache_mtime, time() if ($cache_mtime + WSDL_CACHE_MAX_AGE < time()) { # expired $md5_wsdl = ""; # refetch } } } if (!$md5_wsdl) { $fd = @file($wsdl_fname); if (!$fd) { return $this->raiseSoapFault("Unable to retrieve WSDL", $wsdl_fname); } $file_data = join('', $fd); $md5_wsdl = md5($file_data); if (WSDL_CACHE_USE) { $fp = fopen($cachename, "wb"); fwrite($fp, $file_data); fclose($fp); } } if (WSDL_CACHE_USE && $cache && $cache != $md5_wsdl) { return $this->raiseSoapFault("WSDL Checksum error!", $wsdl_fname); } return $file_data; }