eaccelerator的功能除了对php预编译代码进行优化、缓存之外,还提供了php开发下的共享内存操作、session内存存储、内容缓存等功能。
php默认的session存储方式是在磁盘,虽然可以配置php生成的文件目录到内存盘中,但最终还是需要依赖于文件系统,势必产生文件操纵的开销。当网站并发请求很高的时候,还会产生另为一个性能问题:session目录下的文件数目过多,达到操纵系统瓶颈,虽然这时也可以通过配置为多级目录,但依旧无法摆脱文件系统的魔爪。
session.save_path = "N;/path"
eaccelerator专门针对PHP的这个Session存储效率问题,通过使用共享内存技术为我们提供了高效的解决方案。注意,要启用对session支持,再编译安装eaccelerator时需要启用-with-eaccelerator-sessions选项,例如:
./configure --with-php-config=/usr/local/bin/php-config --enable-eaccelerator=shared --with-eaccelerator-shared-memory --with-eaccelerator-sessions --with-eaccelerator-content-caching --with-eaccelerator-disassembler --with-eaccelerator-debug
然后我们便可以在php.ini中修改配置来启用它:
session.save_handler = eaccelerator
最后重启apache,并执行如下测试:session.php
/**
* new session hander test.
* by lowell from www.zhongguowen.com
*/
if (! function_exists ( "eaccelerator_set_session_handlers" ) )
{
die ( "eaccelerator is in trouble!" );
}
switch ( $_GET [ "act" ] )
{
case "logout":
session_unset ( );
session_destroy ( );
header ( "Location: " . $_SERVER [ "PHP_SELF" ] );
break;
case "login":
$_SESSION["user"] = "Lowell Zhong";
header("Location: " . $_SERVER["PHP_SELF"]);
break;
}
if(isset($_SESSION["user"]) && $_SESSION["user"] != "")
{
echo "Welcome <strong>" . $_SESSION["user"] . "</strong> [<a href=/"?act=logout/">logout</a>]/n";
}else{
echo "<a href=/"?act=login/">Click me</a> for logining";
}
?>
这里再推荐另外还一个php session的共享内存存储模块:http://www.ossp.org/pkg/lib/mm/