问题描述:
我的phpcms网站caches目录下的错误日志中出现了大量的报错,基本都是一样的:
<?php exit;?>11-24 20:35:01 | 8192 | preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead | phpcms\libs\classes\template_cache.class.php | 91 <?php exit;?>11-24 20:35:39 | 8192 | preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead | caches\caches_model\caches_data\content_output.class.php | 42现在日志文件已经非常大了,这是为什么?怎么解决啊?
解决方法:
错误原因分析:
错误信息的大体意思是:preg_replace()函数正则传参中的/e模式已经不推荐使用,建议使用preg_replace_callback()函数来代替之。
后面是错误文件位置,从错误文件路径可以追踪到出错程序位置进而来排查错误修改程序。
在php版本不断更新中,现在已经有很多站长在自己的服务器上部署php5,那么在现在php5还相对来说是高版本的情况下,会有一些函数被修改或废弃,preg_replace()函数的传参正则表达式中的/e模式在php5中已经被废弃,推荐使用preg_replace_callback()来代替回调功能。
从错误信息中的文件路径中我们知道使用到这个函数的地方主要是针对模板编译和编辑器文本内容处理时,这两个地方代码被运行的还是很频繁的,所以错误日志中会大量充斥相关错误信息导致caches/error_log.php文件非常大。
解决方法:
打开文件:phpcms/libs/classes/template_cache.class.php
在大约91行开始,依次找到:
$str = preg_replace("/{(\$[a-zA-Z0-9_[]’"$\x7f-\xff]+)}/es", “$this->addquote(’<?php echo \\1;?>’)”,$str);
替换为:
$str = preg_replace_callback(
“/{(\$[a-zA-Z0-9_[]’”$\x7f-\xff]+)}/s",
function($matches){
return t h i s − > a d d q u o t e ( ′ < ? p h p e c h o ′ . this->addquote('<?php echo '. this−>addquo