本文整理汇总了PHP中Memcached::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::instance方法的具体用法?PHP Memcached::instance怎么用?PHP Memcached::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: driver
/**
* Create a new cache driver instance, based on its lowercase identifier
*
* @param string|array s
* @param string The lowercase cache driver name
* @return Cache\Driver\* A new instance to the cache driver
* @throws \BadMethodCallException Thrown when the
*/
private static function driver($driver)
{
switch ($driver) {
case 'apc':
return new Driver\APC(static::$configuration['key']);
case 'file':
return new Driver\File(static::$configuration['key'], static::$configuration['path']);
case 'memcache':
return new Driver\Memcache(static::$configuration['key'], Memcache::instance());
case 'memcached':
return new Driver\Memcached(static::$configuration['key'], Memcached::instance());
default:
throw new \InvalidArgumentException('Cachew driver [' . $driver . '] is not currently supported');
break;
}
}
示例2: __construct
public function __construct()
{
$this->memcached = Memcached::instance();
include BASE_PATH . '/libraries/known_services.php';
$this->known_services = $known_services;
}
示例3: long_url
/**
* long_url
*
* Expand a shortened URL to its original, long form
*
* @param string short_url
* @return mixed
*/
public function long_url($short_url)
{
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_URL, $short_url);
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curlh, CURLOPT_TIMEOUT, 10);
curl_setopt($curlh, CURLOPT_USERAGENT, 'LongURL API');
curl_setopt($curlh, CURLOPT_REFERER, 'http://longurl.org');
curl_setopt($curlh, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlh, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curlh, CURLOPT_MAXREDIRS, 10);
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlh, CURLOPT_HEADER, true);
// Include header in output
curl_setopt($curlh, CURLOPT_NOBODY, true);
// Don't include body in output
$response = curl_exec($curlh);
$info = curl_getinfo($curlh);
if ($info['http_code'] === 405) {
// HEAD requests aren't allowed
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_URL, $short_url);
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curlh, CURLOPT_TIMEOUT, 10);
curl_setopt($curlh, CURLOPT_USERAGENT, 'LongURL API');
curl_setopt($curlh, CURLOPT_REFERER, 'http://longurl.org');
curl_setopt($curlh, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlh, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curlh, CURLOPT_MAXREDIRS, 10);
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlh, CURLOPT_HEADER, true);
// Include header in output
$response = curl_exec($curlh);
$info = curl_getinfo($curlh);
}
if (!$response) {
$error = curl_error($curlh);
if (strpos($error, 'timed out') !== false) {
Glucose::instance()->response->addHeader('HTTP/1.1 504 Gateway Timeout', true, 504);
error_log($error . ':' . $short_url);
Glucose::fatalError('Connection timeout');
} else {
Glucose::instance()->response->addHeader('HTTP/1.1 400 Bad Request', true, 400);
error_log($error . ':' . $short_url);
Glucose::fatalError('Could not expand URL. Please check that you have submitted a valid URL.');
}
}
curl_close($curlh);
if ($response) {
// Cache content-type
Memcached::instance()->set('content-type:' . $info['url'], $info['content_type']);
// Extract and cache all redirects
preg_match_all('#Location:\\s?([^\\s]+)#i', $response, $matches);
Memcached::instance()->set('all-redirects:' . $short_url, $matches[1]);
// Cache response-code
Memcached::instance()->set('response-code:' . $info['url'], $info['http_code']);
return $info['url'];
} else {
return false;
}
}