本文整理汇总了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;
}