我完整的Lumen应用程序在一年后突然停止工作,生产系统没有出现问题(几乎任何页面都有例外(。由于我没有更改任何代码(至少不太清楚(,我想这可能是托管环境中背景更改的问题。
这一切都始于一个NotFoundHttpException:
(1/1) NotFoundHttpException
in RoutesRequests.php (line 226)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 164)
at Application->LaravelLumenConcerns{closure}()
in RoutesRequests.php (line 413)
at Application->sendThroughPipeline(array(), object(Closure))
in RoutesRequests.php (line 166)
at Application->dispatch(null)
in RoutesRequests.php (line 107)
at Application->run()
in index.php (line 32)
经过一些研究,我在SO:NotFoundHttpException上找到了一个解决方案,使用Lumen
看起来这个问题可以通过推杆来解决:
$app->run(
$app->make('request')
);
转换为index.php.
然而,现在我在视图中的所有链接都已断开-示例:
<link rel="icon" type="image/png" sizes="96x96" href="https://:/images/app/favicon-96x96.png">
<link rel="stylesheet" href="https://:/css/base.css">
URL在Lumen/src/helpers.php中生成:
/**
* Generate a url for the application.
*
* @param string $path
* @param mixed $parameters
* @param bool $secure
* @return string
*/
function url($path = null, $parameters = [], $secure = null)
{
return app('url')->to($path, $parameters, $secure);
}
似乎所有参数都被正确地传递了:例如,$path是/images/app/apple-icon-57x57.png
,而其他参数是空/null。
更新:经过一段时间的搜索,我已经认识到:
命名空间Symfony\Component\HttpFoundation;
class Request
{
// ...
/**
* Gets the scheme and HTTP host.
*
* If the URL was called with basic authentication, the user
* and the password are not added to the generated string.
*
* @return string The scheme and HTTP host
*/
public function getSchemeAndHttpHost()
{
return $this->getScheme().'://'.$this->getHttpHost();
}
// ...
}
正在传递错误的方案(没有SSL(和空主机。但我仍然不知道为什么会发生这种情况。
经过一段时间的寻找,我仍然不知道这可能是从哪里来的。有没有人遇到过类似的问题,或者可以帮我解决这个问题?
在从Lumen 5.5更新到Lumen 5.7并将PHP从7.0更新到7.2.9之后,问题已经部分消失。尽管如此,我还是不得不删除:
$app->make('request')
Lumen的NotFoundHttpException解决方案在我的情况下不起作用,仍然存在一些异常。更好的解决方案或解释仍然非常受欢迎!