Lumen throws 500 sometimes when sending API reques

2019-09-10 06:53发布

I am developing an application using anuglarJs on client side and Lumen in server side for REST API's. My .env configuration given below,

APP_ENV=local
APP_DEBUG=TRUE
APP_KEY=XrPbyRlU5p0szSw5MrAQWwWim8C0MXjT

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=kainfo
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file

And enabled Dotenv::load(__DIR__.'/../'); in bootstrap/app.php

My problem is,sometimes Lumen throws 500 exception and working well on next refresh request. lumen

The Error log is ,

[2015-06-06 07:51:41] lumen.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'' in C:\xampp\htdocs\Study\kasrodinfo\web\vendor\illuminate\database\Connectors\Connector.php:47

2条回答
狗以群分
2楼-- · 2019-09-10 07:13

You need to change the database,username,password in \vendor\laravel\lumen-framework\config\database.php file

查看更多
再贱就再见
3楼-- · 2019-09-10 07:22

Also affected by this, here is what we have found on this issue:

We were using Apache 2.4 with the Event MPM and a thread-safe build of PHP 7. This caused the env() method to not respond reliably - it could give you the right variable at one point in the code, then just a few rows down it would return something else. (Like the default variable which trevorg was experiencing.)

We switched to using the prefork MPM and the problems vanished instantly.

Yes, prefork sucks in terms of speed when compared to another MPM, but it seems there is some issue with the event MPM and environmental variables in Apache, PHP and/or Laravel/Lumen.

查看更多
登录 后发表回答