|
本帖最后由 昨夜渡轮 于 2014-2-23 18:34 编辑
当我们访问如:http://www.ex.com/index.php/welcome/index?page=8
该类中的方法function _fetch_uri_string()其中执行这段代码时:
PHP复制代码
// Let's try the REQUEST_URI first, this will work in most situations
if ($uri = $this->_detect_uri())
{
$this->_set_uri_string($uri);
return;
}
复制代码
我们得到的$this->uri->uri_string是这样的:welcome/index
查看了私有方法private function _detect_uri()发现最后这段代码:
替换掉了“/”斜杠。
如果该类中的方法function _fetch_uri_string()其中执行这段代码时:
PHP复制代码
// Is there a PATH_INFO variable?
// Note: some servers seem to have trouble with getenv() so we'll test it two ways
$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
if (trim($path, '/') != '' && $path != "/".SELF)
{
$this->_set_uri_string ($path);
return;
}
复制代码
我们得到的$this->uri->uri_string是这样的:/welcome/index
如果该类中的方法function _fetch_uri_string()其中执行这段代码时:
PHP复制代码
// No PATH_INFO?... What about QUERY_STRING?
$path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') != '')
{
$this->_set_uri_string ($path);
return;
}
复制代码
我们得到的$this->uri->uri_string是这样的:page=8
同时这里涉及到CI自带的文件缓存OUTPUT类中的function _write_cache($output)和function _display_cache(&$CFG, &$URI)这二个方法中这段代码:
PHP复制代码
$uri = $CFG->item('base_url').
$CFG->item('index_page').
$URI->uri_string;
复制代码
缓存文件名$uri,当URI类中的方法function _fetch_uri_string()其中执行这段代码且满足条件时:
PHP复制代码
// Let's try the REQUEST_URI first, this will work in most situations
if ($uri = $this->_detect_uri())
{
$this->_set_uri_string($uri);
return;
}
复制代码
当我们访问如:
http://www.ex.com/index.php/welcome/index?page=1
http://www.ex.com/index.php/welcome/index?page=2
http://www.ex.com/index.php/welcome/index?page=3
http://www.ex.com/index.php/welcome/index?page=4
http://www.ex.com/index.php/welcome/index?page=5
这样的网址时,缓存文件名$uri一直都是md5('http://www.ex.com/index.php/welcome/index')导致访问多个不同的页面只能用同一文件名来缓存,导致缓存无效。
为什么URI类中private function _detect_uri()方法要用这段代码去掉$_SERVER['QUERY_STRING']部份(page=8):
PHP复制代码
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
if (strncmp($uri, '?/', 2) === 0)
{
$uri = substr($uri, 2);
}
$parts = preg_split('#\?#i', $uri, 2);
$uri = $parts[0];
if (isset($parts[1]))
{
$_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET);
}
else
{
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
复制代码
大家有什么好的建议?请各位老大指点。
同时对于CI缓存目录考虑性能问题我打算用如下方法:
PHP复制代码
crc32($uri)%1000; //用取余的方法来生成1000个目录分布存储
复制代码
这样应该能够满足一般网站的访问量了吧?
|
|