使用eAccelerator有很长一段时间了,也遇到过一些问题,今天查了下手册,记录一下,呵呵
先附上现在的配置文件:
问题一:eAccelerator在不同域名下缓存的结果不一样?同一台服务器岂不是浪费内存和mysql了
查看手册,找到参数eaccelerator.name_space
官方文档如下
这个似乎是解决不同域名不同缓存的关键,哎,俺又有好习惯,key命名的时候都考虑到这个了,呵呵
继续看相关的函数
里面2个名词:user cache user content
暂且可以理解为用户级别的缓存,回头再想缓存不是包括2部分么:
系统级别的缓存:编译后的 PHP 字节码放在内存中,然后下次访问的时候就执行内存中相应文件的字节码并输出给客户端,这些操作都是自动进行的,无需用户进行干预
用户级别的缓存:就是可以在程序中根据实际的需要进行一些变量的缓存操作
ok,这样,在php.ini配置文件里面加上eaccelerator.name_space,收工!
先附上现在的配置文件:
extension="eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.allowed_admin_path = "/opt/www/control"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.allowed_admin_path = "/opt/www/control"
问题一:eAccelerator在不同域名下缓存的结果不一样?同一台服务器岂不是浪费内存和mysql了
查看手册,找到参数eaccelerator.name_space
官方文档如下
引用
When using the user cache api for storing data in shared memory, all keys are prepended by the hostname used for the current request. This hostname equals the ServerName? set in the vhost section of apache. This is done to avoid duplicate keys between vhosts. Sometimes this behaviour is desired to share data between vhosts. When setting this option this namespace is used to prepend to each key. By default this is set to "" which instructs eAccelerator to use the hostname as namespace.
When setting this in the main PHP configuration file this namespace will be used by all vhosts. This value can also be set in the vhost section or even in a .htaccess file to allow sharing of data between only two vhosts.
eaccelerator.name_space = ""
When setting this in the main PHP configuration file this namespace will be used by all vhosts. This value can also be set in the vhost section or even in a .htaccess file to allow sharing of data between only two vhosts.
eaccelerator.name_space = ""
这个似乎是解决不同域名不同缓存的关键,哎,俺又有好习惯,key命名的时候都考虑到这个了,呵呵
继续看相关的函数
引用
eaccelerator.keys | session | content
These settings control the places eAccelerator may cache user content. Possible values are:
shm_and_disk cache data in shared memory and on disk (default value)
shm cache data in shared memory or on disk if shared memory is full or data size greater then "eaccelerator.shm_max"
shm_only cache data in shared memory
disk_only cache data on disk
none don't cache data
eaccelerator.keys = "shm_and_disk"
eaccelerator.sessions = "shm_and_disk"
eaccelerator.content = "shm_and_disk"
These settings control the places eAccelerator may cache user content. Possible values are:
shm_and_disk cache data in shared memory and on disk (default value)
shm cache data in shared memory or on disk if shared memory is full or data size greater then "eaccelerator.shm_max"
shm_only cache data in shared memory
disk_only cache data on disk
none don't cache data
eaccelerator.keys = "shm_and_disk"
eaccelerator.sessions = "shm_and_disk"
eaccelerator.content = "shm_and_disk"
里面2个名词:user cache user content
暂且可以理解为用户级别的缓存,回头再想缓存不是包括2部分么:
系统级别的缓存:编译后的 PHP 字节码放在内存中,然后下次访问的时候就执行内存中相应文件的字节码并输出给客户端,这些操作都是自动进行的,无需用户进行干预
用户级别的缓存:就是可以在程序中根据实际的需要进行一些变量的缓存操作
ok,这样,在php.ini配置文件里面加上eaccelerator.name_space,收工!
网上关于xdebug安装的文章很多了,这里不啰嗦了,一笔带过
安装配置
下载PHP的XDebug扩展,网址:http://xdebug.org/
在Linux下编译安装XDebug
老办法
1 phpize
2 ./configure --enable-xdebug
3 make
4 复制modules/xdebug.so 到php的ext目录
5 编辑php.ini,在最下方增加
zend_extension_ts="/opt/php5/xdebug.so"
xdebug.profiler_enable=on
xdebug.trace_output_dir="/tmp/xdebug"
xdebug.profiler_output_dir="/tmp/xdebug"
xdebug.profiler_output_name="cachegrind.out.%s"
注意:xdebug.profiler_output_name 这一步折腾了很久,直接copy文档的说明吧
使用 xdebug.profiler_output_name="cachegrind.out.%s" 的目的是生成类似cachegrind.out._home_httpd_html_test_xdebug_test_php的文件名,方便调试,因为我是在一个百万级别网站上使用,产生的文件很多很多,如果不这么做,很不方便
6 设置文件权限
mkdir -p /tmp/xdebug
chmod 755 /tmp/xdebug
chown nobody:nobody /tmp/xdebug
7 重启apache
8 分析php
WinCacheGrind下载地址:http://sourceforge.net/projects/wincachegrind/
将/tmp/xdebug下面 cachegrind.out.*_php 文件下载到windows下面分析吧
安装配置
下载PHP的XDebug扩展,网址:http://xdebug.org/
在Linux下编译安装XDebug
老办法
1 phpize
2 ./configure --enable-xdebug
3 make
4 复制modules/xdebug.so 到php的ext目录
5 编辑php.ini,在最下方增加
zend_extension_ts="/opt/php5/xdebug.so"
xdebug.profiler_enable=on
xdebug.trace_output_dir="/tmp/xdebug"
xdebug.profiler_output_dir="/tmp/xdebug"
xdebug.profiler_output_name="cachegrind.out.%s"
注意:xdebug.profiler_output_name 这一步折腾了很久,直接copy文档的说明吧
引用
xdebug.profiler_output_name
Type: string, Default value: cachegrind.out.%p
This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name.
See the xdebug.trace_output_name documentation for the supported specifiers.
Type: string, Default value: cachegrind.out.%p
This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name.
See the xdebug.trace_output_name documentation for the supported specifiers.
引用
xdebug.trace_output_name
Type: string, Default value: trace.%c
This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name. The '.xt' extension is always added automatically.
The possible format specifiers are:
Specifier Meaning Example Format Example Filename
%c crc32 of the current working directory trace.%c trace.1258863198.xt
%p pid trace.%p trace.5174.xt
%r random number trace.%r trace.072db0.xt
%s script name2 cachegrind.out.%s cachegrind.out._home_httpd_html_test_xdebug_test_php
%t timestamp (seconds) trace.%t trace.1179434742.xt
%u timestamp (microseconds) trace.%u trace.1179434749_642382.xt
%H $_SERVER['HTTP_HOST'] trace.%H trace.kossu.xt
%R $_SERVER['REQUEST_URI'] trace.%R trace._test_xdebug_test_php_var=1_var2=2.xt
%S session_id (from $_COOKIE if set) trace.%S trace.c70c1ec2375af58f74b390bbdd2a679d.xt
%% literal % trace.%% trace.%%.xt
Type: string, Default value: trace.%c
This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name. The '.xt' extension is always added automatically.
The possible format specifiers are:
Specifier Meaning Example Format Example Filename
%c crc32 of the current working directory trace.%c trace.1258863198.xt
%p pid trace.%p trace.5174.xt
%r random number trace.%r trace.072db0.xt
%s script name2 cachegrind.out.%s cachegrind.out._home_httpd_html_test_xdebug_test_php
%t timestamp (seconds) trace.%t trace.1179434742.xt
%u timestamp (microseconds) trace.%u trace.1179434749_642382.xt
%H $_SERVER['HTTP_HOST'] trace.%H trace.kossu.xt
%R $_SERVER['REQUEST_URI'] trace.%R trace._test_xdebug_test_php_var=1_var2=2.xt
%S session_id (from $_COOKIE if set) trace.%S trace.c70c1ec2375af58f74b390bbdd2a679d.xt
%% literal % trace.%% trace.%%.xt
使用 xdebug.profiler_output_name="cachegrind.out.%s" 的目的是生成类似cachegrind.out._home_httpd_html_test_xdebug_test_php的文件名,方便调试,因为我是在一个百万级别网站上使用,产生的文件很多很多,如果不这么做,很不方便
6 设置文件权限
mkdir -p /tmp/xdebug
chmod 755 /tmp/xdebug
chown nobody:nobody /tmp/xdebug
7 重启apache
8 分析php
WinCacheGrind下载地址:http://sourceforge.net/projects/wincachegrind/
将/tmp/xdebug下面 cachegrind.out.*_php 文件下载到windows下面分析吧
小折腾了一下,写了个简单的函数,可以实现文本内容中空行的合并
代码很垃圾,呵呵,先放着用吧,如果文本内有html标题,可以用strip_tags先过滤
/**
/**
* 合并文本内空行
*
* @param string string - 传递进去的文本内容
* @return string 返回替换后的结果
*/
function mergebr($string){
$string = trim(nl2br($string));
$string = preg_replace('/\s(?=\s)/', '', $string);
$string = preg_replace('/[\n\r\t]/', '', $string);
//合并换行符
$no = sizeof(explode("<br /><br />", $string));
for($i=0;$i<$no ;$i++ ){
if(eregi("<br /><br />",$string)){
$string = str_replace("<br /><br />", "<br />", $string);
}else{
break;
}
}
return $string;
}
代码很垃圾,呵呵,先放着用吧,如果文本内有html标题,可以用strip_tags先过滤
/**
/**
* 合并文本内空行
*
* @param string string - 传递进去的文本内容
* @return string 返回替换后的结果
*/
function mergebr($string){
$string = trim(nl2br($string));
$string = preg_replace('/\s(?=\s)/', '', $string);
$string = preg_replace('/[\n\r\t]/', '', $string);
//合并换行符
$no = sizeof(explode("<br /><br />", $string));
for($i=0;$i<$no ;$i++ ){
if(eregi("<br /><br />",$string)){
$string = str_replace("<br /><br />", "<br />", $string);
}else{
break;
}
}
return $string;
}
遇到个小问题,需要对多维数组中重复数据进行处理,php也没有现成的函数可以用,自己随便搞了下
$tmparr = array();
foreach($oldarr as $value){
$tmparr[] = serialize($value);
}
$tmparr = array_unique($tmparr);
foreach($tmparr as $value){
$newarr[] = unserialize($value);
}
很奇怪的处理方法,简单好用就行,呵呵
$tmparr = array();
foreach($oldarr as $value){
$tmparr[] = serialize($value);
}
$tmparr = array_unique($tmparr);
foreach($tmparr as $value){
$newarr[] = unserialize($value);
}
很奇怪的处理方法,简单好用就行,呵呵
服务器的空间越来越小,今天终于找到罪魁祸首
查看apache的日志,错误日志55g
杀了我得了,赶紧的清空
然后看日志找原因,大量的
EACCELERATOR hit:
...
记录
原来是开启了eAccelerator的debug选项
修改php.ini,eaccelerator.debug="0"
重启apche,error_log停止疯长了,哈哈
引用一段
偶的硬盘终于回来啦,哈哈
查看apache的日志,错误日志55g

杀了我得了,赶紧的清空
然后看日志找原因,大量的
EACCELERATOR hit:
...
记录
原来是开启了eAccelerator的debug选项
修改php.ini,eaccelerator.debug="0"
重启apche,error_log停止疯长了,哈哈
引用一段
引用
如果你打开了eAccelerator的debug选项,可以从日志中看到类似下面的信息
EACCELERATOR hit:
...
以上信息表示文件都得到了缓存和命中。
EACCELERATOR hit:
...
以上信息表示文件都得到了缓存和命中。
偶的硬盘终于回来啦,哈哈
