白屏死机 - 在 PHP/Vagrant 环境中没有显示错误 (Yii)
我不确定这个问题是否部分是由于 vagrant 造成的,但是我在运行 Unix 的 Vagrant 机器中安装了 Yii 1.x.
I cannot be sure if this problem is partly due to the vagrant, however I have a Yii 1.x installation within a Vagrant box running Unix.
我正在尝试强制执行一个简单的 PHP 错误,例如控制器中缺少分号,即使我 100% 确定我创建了一个错误,但我没有看到带有堆栈跟踪的标准 Yii 错误页面.这在以前是有效的,尽管最近的某些事情似乎以这种方式停止了这种工作.
I am trying to force a simple PHP error such as a missing semi-colon in a controller, even though I am 100% sure I have a created an error I do not see the standard Yii error page with the stack trace. This has worked previously although it would seem something recent has stopped this working in this way.
奇怪的是 - Yii 在脚本底部输出数据库查询(这是有意的,但我不明白为什么 Yii 只显示数据库查询.
The weird thing is - Yii is outputting the Database queries at the bottom of the script (this is intended but I cannot understand why Yii is only showing the DB queries.
我的个人配置如下:(只显示其中的一部分..)
My personal config looks as follows: (only showing part of it..)
我已经尝试了下面的代码 &检查日志但没有快乐
I have tried the code below & check the logs but no joy
ini_set('display_errors',true);
error_reporting(E_ALL);
任何人都可以提出任何想法...
Can anyone suggest any ideas...
return array(
'yiiDebug' => true,
'yiiTraceLevel' => 6,
.....
'components'=>array(
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
'web' => array(
'class' => 'CWebLogRoute',
'levels' => 'profile, trace, info, error, warning, application', // profile, trace, info, error, warning, application
'showInFireBug' => false
),
'file' => array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning, watch', // error, warning, watch
'categories' => 'system.*',
),
array(
'class' => 'CProfileLogRoute',
'levels' => 'error, warning, trace, info, profile', // error, warning, trace, info, profile
),
),
),
),
例如……在我的一个控制器中,我有以下代码:
So for instance... in one of my controllers I have the following code:
public function actionDelete($id)
{
$model = $this->loadModel($id);
5e55 // added error here on purpose
}
我希望第 2 行出现关于 5e55 的错误,但没有收到错误,我看到的只是白屏(加上显示所有查询等的 Yii 应用程序日志)- 如果我删除 yii 配置内容以输出查询,我会得到 100% 的白色/空白屏幕.
I would expect an error on the 2nd line in regards to the 5e55 that has no place being there, however rather than receive an error all I see is a white screen (plus the Yii application log that shows all the queries etc) - if I remove the yii config stuff to output queries I get a 100% white/blank screen.
我尝试在 index.php 引导文件中添加各种内容,但没有任何乐趣,我的配置看起来相对正常,但我不明白为什么将错误报告给浏览器或我的日志.
I have tried adding various things to the index.php bootstrap file but without any joy, my config looks relatively normal but I cannot understand why the error is being reported to the browser or my logs.
推荐答案
你已经通过设置做了正确的事情
You've done the right thing by setting
ini_set('display_errors',true);
error_reporting(E_ALL);
...但有几个原因导致这实际上可能不会生效.
...but there are a few reasons why this might not actually take effect.
1) 错误报告可能会被脚本中的稍后"再次关闭.因为这些设置基本上只是全局变量,任何人都可以设置它们,并且大多数框架都有禁用它们的地方.根据您的代码包含"的位置,链中的其他内容很可能称为 display_errors - false.
1) Error reporting might be getting turned off again by something 'later' in the script. Because these settings are basically just global variables anyone can set them and most frameworks have somewhere they're disabled. Depending on where your code got 'included' something else in the chain might well have called display_errors - false.
2) 可以在运行时禁用更改设置.您的环境可能有类似 php_admin_flag 的指令来阻止 display_errors 被打开.
2) Changing settings can be disabled at run time. Your environment might have something like php_admin_flag directives to stop display_errors being turned on.
如果您能够获得输出,请尝试运行它以转储所有 ini 设置的状态:
If you're able to get output at all, try running this to dump the state of all the ini settings:
var_dump(ini_get_all());
但我认为可能发生的事情是您在自己的一个文件中有一个小的语法错误,而解释器完全放弃了该代码.它从未执行过,因此您的 display_errors 设置甚至没有运行.
BUT what I think is probably happening is you have a small syntax error in one of your own files, and the interpreter is giving up on that code entirely. It's never executed, and so your display_errors setting isn't even getting run.
正如其他人所建议的那样,查看您的错误日志可能会告诉您发生了什么.
As others have suggested a look at your error logs will probably tell you what's going on.
另一种笨拙但有用的方法是尝试在命令行上执行您的文件,看看它是否给出了语法警告.我对 Yii 不熟悉,但找到你最近编辑过的文件并运行:
Another hacky but useful way is to try and execute your files on the command line and see if it gives a syntax warning. I'm not familiar with Yii but find the files you've edited recently and run this:
php -f yourproject/somefile_ofyours.php
它可能会吐出这样的错误:
It will probably spit out an error like this:
PHP Parse error: syntax error, unexpected 'xxxxx' (T_STRING) in somefile_ofyours.php on line 27
相关文章