我在使用 HHVM 安装 Laravel Homestead 时遇到了同样的问题。如果你在你的路由文件中输入一些像sdfkjl 这样的随机垃圾,你会得到一个空白页(但是,如果添加一个分号sdfkjl; 你会得到错误输出)。这些错误被记录在/var/log/hhvm/error.log,但它们不会进入浏览器,而是你只会得到一个空白页面。这似乎是 HHVM 的故意行为。 Laravel 似乎也试图处理这些,但没有捕捉到 HHVM 发送的一些致命错误。感谢 this github issue 提供的线索,我决定对 Laravel 的 Foundation\Bootstrap\HandleExceptions.php 做些小改动,看看我是否可以让它捕捉到所有这些致命问题:
首先,更新您的/etc/hhvm/php.ini 并添加以下设置:
hhvm.server.implicit_flush = true
hhvm.error_handling.call_user_handler_on_fatals = true
在修改包源之前,让我们用这个工匠命令删除vendor\compiled.php:
$ php artisan clear-compiled
让我们将环境会话设置为数组:
在你的 .env
SESSION_DRIVER=array
(您可能还需要清除 storage/framework/sessions 中所有看似随机的会话文件)
现在我们对 Laravel 包源所做的任何更改都会立即反映出来。让我们更新 HandleExceptions 类中的一些内容:
在 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php 中
// **** Add this to hold fatal error
protected static $fatalError = null;
...
public function handleError($level, $message, $file = '', $line = 0, $context = array())
{
// **** Add this, loads fatal error
if ($level & (1 << 24)) {
self::$fatalError = array(
'message' => $message,
'type' => $level,
'file' => $file,
'line' => $line
);
}
if (error_reporting() & $level)
{
throw new ErrorException($message, 0, $level, $file, $line);
}
}
...
// *** Update this function so it can handle the fatal
public function handleShutdown()
{
$error = error_get_last();
if(self::$fatalError){
$error = self::$fatalError;
}
if ( ! is_null($error) && $this->isFatal($error['type']))
{
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
...
protected function isFatal($type)
{
// *** Add type 16777217 that HVVM returns for fatal
return in_array($type, [16777217, E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]);
}
...
现在在您的路线文件夹中输入随机垃圾(无分号),您将看到致命显示。我现在在 Laravel github 上有 reported this issue 给 Taylor。如果你在 Lumen,我有一个 solution here,它可以在 Lumen 得到修复之前工作。