當前位置: 首頁>>代碼示例>>PHP>>正文


PHP xmlrpc_client::SetCurlOptions方法代碼示例

本文整理匯總了PHP中xmlrpc_client::SetCurlOptions方法的典型用法代碼示例。如果您正苦於以下問題:PHP xmlrpc_client::SetCurlOptions方法的具體用法?PHP xmlrpc_client::SetCurlOptions怎麽用?PHP xmlrpc_client::SetCurlOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xmlrpc_client的用法示例。


在下文中一共展示了xmlrpc_client::SetCurlOptions方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: xmlrpc

 /**
  *
  * Call XML RPC method
  * @param string $method
  * @param args mixed[optional]
  * @param _ mixed[optional]
  * @throws waException
  */
 protected function xmlrpc($method, $args = null, $_ = null)
 {
     static $client;
     $params = func_get_args();
     $method = array_shift($params);
     if (count($params) == 1 && is_array(current($params))) {
         $params = current($params);
     }
     $this->log(__METHOD__ . "({$method}) \n" . var_export($params, true), self::LOG_DEBUG);
     if (extension_loaded('curl')) {
         require_once dirname(__FILE__) . '/../../vendors/xmlrpc/lib/init.php';
     }
     if (class_exists('xmlrpc_client')) {
         if (!isset($client)) {
             $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
             $client = new xmlrpc_client($this->xmlrpc_url);
             if ($this->url_pass || $this->url_user) {
                 $client->SetCurlOptions(array(CURLOPT_USERPWD => "{$this->url_user}:{$this->url_pass}"));
             }
             $client->request_charset_encoding = 'utf-8';
         }
         $this->log(__METHOD__ . "({$method}) external lib", self::LOG_DEBUG);
         $request = new xmlrpcmsg($method, array(php_xmlrpc_encode($params)));
         $response = $client->send($request);
         if ($response && ($fault_code = $response->faultCode())) {
             $fault_string = $response->faultString();
             $this->log(__METHOD__ . "({$method}) returns {$fault_string} ({$fault_code})", self::LOG_ERROR);
             throw new waException("{$fault_string} ({$fault_code})", $fault_code);
         }
         return php_xmlrpc_decode($response->value(), array('dates_as_objects' => true));
     } else {
         if (!extension_loaded('xmlrpc')) {
             throw new waException("PHP extension 'xmlrpc' or 'curl' required.");
         }
         $this->log(__METHOD__ . "({$method}) internal PHP lib", self::LOG_DEBUG);
         $request = xmlrpc_encode_request($method, $params, array('encoding' => 'utf-8'));
         $request_options = array('method' => "POST", 'header' => "Content-Type: text/xml" . ($this->url_pass || $this->url_user ? "\nAuthorization: Basic " . base64_encode("{$this->url_user}:{$this->url_pass}") : ''), 'content' => $request);
         $context = stream_context_create(array('http' => $request_options));
         //TODO add curl support
         $retry = 0;
         do {
             ob_start();
             if ($retry) {
                 sleep(6);
             }
             $file = file_get_contents($this->xmlrpc_url, false, $context);
             $log = ob_get_clean();
             if ($log) {
                 $this->log(__METHOD__ . ":\t{$log}", self::LOG_WARNING);
             }
             if (!$file) {
                 $this->log(__METHOD__ . "({$method}) fail open stream", self::LOG_ERROR);
             }
         } while (!$file && ++$counter < 10);
         if (!$file) {
             throw new waException(sprintf(_wp("I/O error: %s"), 'Fail while request WordPress'));
         }
         $response = xmlrpc_decode($file, 'utf-8');
         if ($response && xmlrpc_is_fault($response)) {
             $this->log(__METHOD__ . "({$method}) returns {$response['faultString']} ({$response['faultCode']})", self::LOG_ERROR);
             throw new waException("{$response['faultString']} ({$response['faultCode']})", $response['faultCode']);
         }
     }
     return $response;
 }
開發者ID:nowaym,項目名稱:webasyst-framework,代碼行數:73,代碼來源:blogImportPluginTransport.class.php


注:本文中的xmlrpc_client::SetCurlOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。