本文整理匯總了PHP中Zend_Service_Delicious::_lastRequestTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Service_Delicious::_lastRequestTime方法的具體用法?PHP Zend_Service_Delicious::_lastRequestTime怎麽用?PHP Zend_Service_Delicious::_lastRequestTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Service_Delicious
的用法示例。
在下文中一共展示了Zend_Service_Delicious::_lastRequestTime方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: makeRequest
/**
* Handles all GET requests to a web service
*
* @param string $path Path
* @param array $parms Array of GET parameters
* @param string $type Type of a request ("xml"|"json")
* @return mixed decoded response from web service
*/
public function makeRequest($path, array $parms = array(), $type = 'xml')
{
// if previous request was made less then 1 sec ago
// wait until we can make a new request
$timeDiff = microtime(true) - self::$_lastRequestTime;
if ($timeDiff < 1) {
usleep((1 - $timeDiff) * 1000000);
}
$this->_rest->getHttpClient()->setAuth($this->_authUname, $this->_authPass);
switch ($type) {
case 'xml':
$this->_rest->setUri(self::API_URI);
break;
case 'json':
$parms['raw'] = true;
$this->_rest->setUri(self::JSON_URI);
break;
default:
/**
* @see Zend_Service_Delicious_Exception
*/
require_once 'Zend/Service/Delicious/Exception.php';
throw new Zend_Service_Delicious_Exception('Unknown request type');
}
self::$_lastRequestTime = microtime(true);
$response = $this->_rest->restGet($path, $parms);
if (!$response->isSuccessful()) {
/**
* @see Zend_Service_Delicious_Exception
*/
require_once 'Zend/Service/Delicious/Exception.php';
throw new Zend_Service_Delicious_Exception("Http client reported an error: '{$response->getMessage()}'");
}
$responseBody = $response->getBody();
switch ($type) {
case 'xml':
$dom = new DOMDocument() ;
if (!@$dom->loadXML($responseBody)) {
/**
* @see Zend_Service_Delicious_Exception
*/
require_once 'Zend/Service/Delicious/Exception.php';
throw new Zend_Service_Delicious_Exception('XML Error');
}
return $dom;
case 'json':
return Zend_Json_Decoder::decode($responseBody);
}
}
示例2: makeRequest
/**
* Handles all GET requests to a web service
*
* @param string $path Path
* @param array $parms Array of GET parameters
* @param string $type Type of a request xml|json
* @return DOMDocument response from web service
*/
public function makeRequest($path, $parms = array(), $type = 'xml')
{
settype($parms, 'array');
// if previous request was made less then 1 sec ago
// wait until we can make a new request
$timeDiff = microtime(true) - self::$_lastRequestTime;
if ($timeDiff < 1) {
usleep((1 - $timeDiff) * 1000000);
}
$this->_http->resetParameters();
foreach ($parms as $f_parm => $f_value) {
$this->_http->setParameterGet($f_parm, $f_value);
}
switch ($type) {
case 'xml':
$this->_http->setUri(self::API_URI . $path);
break;
case 'json':
$this->_http->setUri(self::JSON_URI . $path);
$this->_http->setParameterGet('raw', true);
break;
default:
throw new Zend_Service_Delicious_Exception('Unknown request type');
}
self::$_lastRequestTime = microtime(true);
$response = $this->_http->request(Zend_Http_Client::GET);
if (!$response->isSuccessful()) {
throw new Zend_Service_Delicious_Exception("Http client reported an error: '{$response->getMessage()}'");
}
$responseBody = $response->getBody();
switch ($type) {
case 'xml':
$dom = new DOMDocument();
if (!@$dom->loadXML($responseBody)) {
throw new Zend_Service_Delicious_Exception('XML Error');
}
return $dom;
case 'json':
return Zend_Json::decode($responseBody);
}
}