php - 在我的 linux 服务器上,我收到一个 php 错误,但我看不到错误,为什么?

标签 php linux apache yii phpexcel

我的 php 代码(这是一个导出 pdf 和 excel 的功能,我使用的是 Yii 框架)在我的本地机器上运行良好。 但是当我把代码放在linux服务器上时, 我得到一个错误。我用echo一步步调试,最后发现这一步失败了。 $objWriter->save('php://output'); (使用 PHPExcel)。

但我看不出这是什么错误。

我设置了 display_errors = On,还设置了 error_log。 但我仍然看不到错误信息。

最佳答案

确保你有这些设置:

error_reporting(E_ALL); // or possibly: E_ALL & ~E_NOTICE
ini_set('display_errors', TRUE);
ini_set('scream.enabled', TRUE); // this overrides the @ operator

如果你想要任何错误停止脚本的执行,那么定义一个错误处理函数:

function my_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
    file_put_contents(
        'custom_log_file.log',
        '#'.$errno.' '.$errfile.':'.$errline.' '.$errstr
    );
    // throw new Exception('#'.$errno.' '.$errfile.':'.$errline.' '.$errstr);
    die('#'.$errno.' '.$errfile.':'.$errline.' '.$errstr);
}
set_error_handler('my_error_handler');

如果您选择从您的错误处理函数中抛出异常(您很可能不会期望捕获它——它们只是为了调试目的),您可以设置一个异常处理程序。

function my_exception_handler() {
     // here you code some nice visuals for your error handling
}
set_exception_handler('my_exception_handler');

在这两种情况下,您都可以var_dump(debug_backtrace()); 来查看发生错误的数据上下文。

如果 PHP 文件是第一个访问的(即它的 URL 在浏览器的地址栏中)并且其中有语法错误,则无错误报告机制会显示该错误。

您可以使用 linux CLI php -l filename.php 检查文件中的语法错误。或者您可以创建另一个文件 x.php,其中只包含 filename.php 的包含。

关于php - 在我的 linux 服务器上,我收到一个 php 错误,但我看不到错误,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13034080/

相关文章:

php - 尝试通过 PHP/MySQL 下载 Blob

php - 为什么我的 CKEditor 添加了垃圾代码?

linux - Unix 查找脚本功能改进

java - Apache Camel 调度程序错误 : Failed to resolve endpoint

php - 使用 htaccess 清理 URL

Python - 通过 SSH 运行时字符串变形

linux - 使用tc进行带宽管理的优秀GUI工具

wordpress - Chrome 版本 44.0.2403.xx 的 HTTPS header 问题

windows - Apache 服务器的端口 80 正在被 PID 4(系统)使用,无法停止

php - 缓存 JSON : Apache, PHP、jQuery