When doing several ajax requests the .env file is not always being pulled.
Using Vue with Axios:
NOTE: This does NOT happen every single time, it happens randomly.
getCountries() {
axios.get('/api/countries').then(result => {
this.getLanguages(result.data.id);
}).catch(error => console.log(error) );
},
getLanguages(countryId) {
axios.get('/api/countries/'+countryId+'/languages').then(result => {
// do whatever with it
}).catch(error => {
let keys = Object.keys(error);
keys.forEach(key => console.log(error[key]) );
});
}
# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_database
DB_USERNAME=myUsername
DB_PASSWORD=hereMyPassword
return [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => 'InnoDB',
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
]
"SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from `users` where `id` = 1 and `users`.`deleted_at` is null limit 1)"
method: "get"
timeout: 0
โ
readyState: 4
โ
response: "{\n \"message\": \"SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from `users` where `id` = 1 and `users`.`deleted_at` is null limit 1)\" ... "
responseType: ""
โ
responseXML: null
โ
status: 500
โ
statusText: "Internal Server Error"
โ
timeout: 0
โ
withCredentials: false
โ
exception: "Illuminate/Database/QueryException"
โโ
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
โโ
line: 664
โโ
message: "SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from `users` where `id` = 1 and `users`.`deleted_at` is null limit 1)"
โโ
trace: (52) [โฆ]
โโโ
0: {โฆ}
class: "Illuminate/Database/Connection"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
function: "runQueryCallback"
line: 624
type: "->"
โโโ
1: {โฆ}
class: "Illuminate/Database/Connection"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
function: "run"
line: 333
type: "->"
2: {โฆ}
class: "Illuminate/Database/Connection"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php"
function: "select"
line: 2120
type: "->"
โโโ
3: {โฆ}
class: "Illuminate/Database/Query/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php"
function: "runSelect"
line: 2108
type: "->"
โโโ
4: {โฆ}
class: "Illuminate/Database/Query/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php"
function: "Illuminate/Database/Query/{closure}"
line: 2594
type: "->"
โโโ
5: {โฆ}
class: "Illuminate/Database/Query/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php"
function: "onceWithColumns"
line: 2109
type: "->"
โโโ
6: {โฆ}
class: "Illuminate/Database/Query/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php"
function: "get"
line: 519
type: "->"
โโโ
7: {โฆ}
class: "Illuminate/Database/Eloquent/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php"
function: "getModels"
line: 503
type: "->"
โโโ
8: {โฆ}
class: "Illuminate/Database/Eloquent/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php"
function: "get"
line: 77
type: "->"
โโโ
9: {โฆ}
class: "Illuminate/Database/Eloquent/Builder"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php"
function: "first"
line: 52
type: "->"
โโโ
10: {โฆ}
class: "Illuminate/Auth/EloquentUserProvider"
file: "/var/www/vendor/laravel/passport/src/Guards/TokenGuard.php"
function: "retrieveById"
line: 199
type: "->"
โโโ
11: {โฆ}
class: "Laravel/Passport/Guards/TokenGuard"
file: "/var/www/vendor/laravel/passport/src/Guards/TokenGuard.php"
function: "authenticateViaCookie"
line: 91
type: "->"
โโโ
12: {โฆ}
class: "Laravel/Passport/Guards/TokenGuard"
file: "/var/www/vendor/laravel/passport/src/PassportServiceProvider.php"
function: "user"
line: 274
type: "->"
โโโ
13: {โฆ}
class: "Laravel/Passport/PassportServiceProvider"
function: "Laravel/Passport/{closure}"
type: "->"
โโโ
14: {โฆ}
file: "/var/www/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php"
function: "call_user_func"
line: 58
โโโ
15: {โฆ}
class: "Illuminate/Auth/RequestGuard"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php"
function: "user"
line: 60
type: "->"
โโโ
16: {โฆ}
class: "Illuminate/Auth/RequestGuard"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php"
function: "check"
line: 62
type: "->"
โโโ
17: {โฆ}
class: "Illuminate/Auth/Middleware/Authenticate"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php"
function: "authenticate"
line: 41
type: "->"
โโโ
18: {โฆ}
class: "Illuminate/Auth/Middleware/Authenticate"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
19: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
20: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php"
function: "Illuminate/Routing/{closure}"
line: 58
type: "->"
โโโ
21: {โฆ}
class: "Illuminate/Routing/Middleware/ThrottleRequests"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
22: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
23: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "Illuminate/Routing/{closure}"
line: 104
type: "->"
โโโ
24: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
function: "then"
line: 682
type: "->"
โโโ
25: {โฆ}
class: "Illuminate/Routing/Router"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
function: "runRouteWithinStack"
line: 657
type: "->"
โโโ
26: {โฆ}
class: "Illuminate/Routing/Router"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
function: "runRoute"
line: 623
type: "->"
โโโ
27: {โฆ}
class: "Illuminate/Routing/Router"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
function: "dispatchToRoute"
line: 612
type: "->"
โโโ
28: {โฆ}
class: "Illuminate/Routing/Router"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
function: "dispatch"
line: 176
type: "->"
โโโ
29: {โฆ}
class: "Illuminate/Foundation/Http/Kernel"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Foundation/Http/{closure}"
line: 30
type: "->"
โโโ
30: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php"
function: "Illuminate/Routing/{closure}"
line: 65
type: "->"
โโโ
31: {โฆ}
class: "Barryvdh/Debugbar/Middleware/InjectDebugbar"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
32: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
33: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/fideloper/proxy/src/TrustProxies.php"
function: "Illuminate/Routing/{closure}"
line: 57
type: "->"
โโโ
34: {โฆ}
class: "Fideloper/Proxy/TrustProxies"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
35: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
36: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
function: "Illuminate/Routing/{closure}"
line: 21
type: "->"
โโโ
37: {โฆ}
class: "Illuminate/Foundation/Http/Middleware/TransformsRequest"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
38: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
39: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php"
function: "Illuminate/Routing/{closure}"
line: 21
type: "->"
โโโ
40: {โฆ}
class: "Illuminate/Foundation/Http/Middleware/TransformsRequest"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
41: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
42: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php"
function: "Illuminate/Routing/{closure}"
line: 27
type: "->"
โโโ
43: {โฆ}
class: "Illuminate/Foundation/Http/Middleware/ValidatePostSize"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
44: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
45: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php"
function: "Illuminate/Routing/{closure}"
line: 62
type: "->"
โโโ
46: {โฆ}
class: "Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "handle"
line: 163
type: "->"
โโโ
47: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php"
function: "Illuminate/Pipeline/{closure}"
line: 53
type: "->"
โโโ
48: {โฆ}
class: "Illuminate/Routing/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php"
function: "Illuminate/Routing/{closure}"
line: 104
type: "->"
โโโ
49: {โฆ}
class: "Illuminate/Pipeline/Pipeline"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
function: "then"
line: 151
type: "->"
โโโ
50: {โฆ}
class: "Illuminate/Foundation/Http/Kernel"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php"
function: "sendRequestThroughRouter"
line: 116
type: "->"
โโโ
51: {โฆ}
class: "Illuminate/Foundation/Http/Kernel"
file: "/var/www/public/index.php"
function: "handle"
line: 55
type: "->"
โโโ
status: 500
โ
statusText: "Internal Server Error"
NOTE 2: The paths have been modified in this issue for the sake of security
What web server are you using? If Apache please specify which MPM you are using (worker, prefork etc).
Does the issue persist if you run php artisan config:cache?
I'm fairly sure this relates to this: https://github.com/laravel/framework/issues/24510#issuecomment-395865724
@driesvints - either this issue, or the other one, should probably be left open, since it's clearly an ongoing issue? Leave it with you to decide what to do given it's not likely to be solved. Perhaps some documentation around it?
@Garanaw is your issue solved when running php artisan config:cache like @matt-allan suggested?
You should never use "config:cache" on development environment.
@xuanquynh he noted from the server so I suspect that this is on production?
@xuanquynh yes but you shouldn't be using getenv and putenv from a thread either.
I'm suggesting that they try config:cache because the error is most likely caused by getenv and putenv being called from a thread. If the problem goes away after running config:cache we have narrowed down the problem. If it doesn't go away we know it's a different issue.
I don't agree that you should never run config:cache in development. It's a bit annoying but it doesn't do any harm and in the OPs situation it's better than the alternative.
Apologies for the late response, I've been at work.
@driesvints when I mentioned the server I meant the backend part, but it is local.
@matt-allan It runs in local, I didn't deploy it to production yet. The environment is Wamp64 running on Windows 7, if it gives more info. As for the config:cache I didn't try it yet. Not sure if I should run that command in local for the what the previous comments say?
Not sure if I should for the previous comments?
You shouldn't normally run config:cache in development but in this case I am trying to help debug your issue. If you don't run it I can't help you. You don't normally run config:cache in development because you will need to run config:cache again if you change something:
The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
https://laravel.com/docs/5.8/configuration#configuration-caching
I just need you to run config:cache to test if your issue persists. Afterwards you can just run config:clear to undo it.
The reason I am asking you to run config:cache in this case is because that avoids the putenv function call which is likely causing your problem.
The environment is Wamp64 running on Windows 7, if it gives more info
Their docs don't say what MPM it's using. Can you run phpinfo from a route, then copy the output under Configuration > apache2handler > Loaded Modules into this issue? It should look something like core mod_so http_core worker....
It would also be helpful to know what the value of Thread Safety is, it's at the top of the phpinfo output.
Ok, so, here are the loaded modules:
core mod_win32 mpm_winnt http_core mod_so mod_access_compat mod_actions mod_alias mod_allowmethods mod_asis mod_auth_basic mod_auth_digest mod_authn_core mod_authn_file mod_authz_core mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cache mod_cache_disk mod_dir mod_env mod_file_cache mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_rewrite mod_setenvif mod_userdir mod_vhost_alias mod_php7
And my Thread Safety is enabled.
I just ran the config:cache command, and I'll keep developing "as normal". I'll be updating the issue with the results, whether if the issue persists or if it's gone.
Thanks for the output, that is really helpful.
The winnt MPM uses threads. PHP isn't really thread safe, even with thread safety enabled, and the putenv function is definitely not thread safe.
It's likely you are experiencing the same issue as https://github.com/laravel/framework/issues/24510. There are some workarounds detailed in that issue.
I'm not sure if Laravel can really do anything about this other than updating the docs to mention this issue.
PHP doesn't recommend using a threaded webserver because of issues like this. The standard practice is to only call putenv in the parent thread but you can't do that if you aren't creating the threads yourself.
Laravel tried removing the putenv calls but that broke a lot of things and the change was reverted. There is a fix in PHP 7.4 that will help a little bit but you still might have issues.
@matt-allan thanks for the response. After a quick read to that issue, and knowing that it's a PHP issue, I guess I can live with it in development, I'll keep an eye on production to disable multi threads though. Thank you
You shouldn't normally run config:cache in development
shouldn't ... is more suitable than should never. I experience that nearly all issues relevant to environment and configuration often cause by cache. I need really care about these things again.
@matt-allan Thank you for your clear explanation!
Closing this as it's been determined that it's a php issue, not a Laravel issue.
Most helpful comment
Closing this as it's been determined that it's a php issue, not a Laravel issue.