本文整理匯總了PHP中storage::gethandle方法的典型用法代碼示例。如果您正苦於以下問題:PHP storage::gethandle方法的具體用法?PHP storage::gethandle怎麽用?PHP storage::gethandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類storage
的用法示例。
在下文中一共展示了storage::gethandle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
/**
* 獲取內容並輸出
* 如果stroage裏麵不存在,則從URL裏麵獲取
* */
private function handle($filename, $key, $delete = false, $direct = false)
{
$content = '';
if ($this->succeed) {
$storage = storage::gethandle();
if ($delete) {
if (!$storage->exists($key)) {
die(json_encode(array('purge' => $filename, 'key' => $key, 'success' => 'not exists')));
}
$return = $storage->delete($key);
die(json_encode(array('purge' => $filename, 'key' => $key, 'success' => $return)));
}
if ($storage->exists($key) && !$direct) {
if (!NO_LOCATE && ($url = $storage->url($key))) {
$this->locate($url);
}
$content = $storage->read($key);
$this->hit = $key;
if (empty($content)) {
$this->succeed = false;
$this->error_type = 'empty_conent';
}
} else {
//$content = @file_get_contents(BASE_URL.$filename);
$content = lib::fetch_url(BASE_URL . $filename);
if (!is_array($content) || count($content) < 2) {
$this->succeed = false;
$this->error_type = 'fetch_error';
} elseif ($content[0] == 200) {
//返回200,才寫入
if (!$direct) {
$storage->write($key, $content[1]);
}
} else {
header('HTTP/1.1 ' . $content[0]);
}
$content = $content[1];
}
}
//顯示內容
$this->render($content);
}