-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config('value') is not working on cron #16333
Comments
The issue you shared contains everything that can be said basically :) Not sure why you opened a new issue. |
@themsaid I can't solve the problem. Any suggestion that I can do? |
When you say |
@themsaid yes, I am using laravel schedular. And I know, [
"sm_api" => "my-api-url",
"mailgun" => [
"domain" => "mailgun-domain",
"secret" => "mailgun-secret",
],
"ses" => [
"key" => null,
"secret" => null,
"region" => "us-east-1",
],
"sparkpost" => [
"secret" => null,
],
"stripe" => [
"model" => "App\User",
"key" => null,
"secret" => null,
],
] but in the cron it returns this- [
"mailgun" => [
"domain" => null,
"secret" => null,
],
"ses" => [
"key" => null,
"secret" => null,
"region" => "us-east-1",
],
"sparkpost" => [
"secret" => null,
],
"stripe" => [
"model" => "App\User",
"key" => null,
"secret" => null,
],
] I also checked the |
Did you try changing environment to production after caching configurations? |
@lkmadushan yes, I tried. but nothing happens. And in >>> config('app.env')
=> "production"
>>> env('APP_ENV')
=> null It's really weird. |
@themsaid I think, in the |
It is weird. I'm working on linux mint (Ubuntu 14.04.2 LTS) on a homestead machine (Ubuntu 16.04 LTS) with PHP 7.0.8, laravel/framework v5.3.22 and I can't reproduce your problem. Furthermore: I am sending mails – triggered from the schedule method / cron – that successfully fetch a lot of config values. Brief tests have shown that config values are read on my system:
Output for APP_ENV=production:
We also have custom configuration values in services and they show up in the log properly. The output matches the output in artisan tinker:
php artisan tinker shows our custom services very well. No differences to the output from schedule. Maybe something is messed up on your system? Your example
lets me think that env('APP_ENV') is always null on your system, because config('app.env') is resolved with fallback 'production'. You can see that in config/app.php:
Maybe something on your system prevents setting environment variables? |
Also, have a look at your crontab and compare it to the one, homestead set up for me: /etc/cron.d/{appname}app <- root:root -rw-r--r--
[edit] the file-owner shouldn't be root I guess. It's an ntfs mounted ssd with vagrant / homestead "nfs" option for shared folders, so this aspect might not be of relevance. |
The .env file is not loaded (accurate for 5.2 and 5.3) if you have cached your configuration files. This is the intended behavior. You should only call env() from your config files to help build the cached configuration, and then call config() in your code. |
@sisve, I am doing that exactly. I am using this bit of code |
Yes, 1) you have an old cached configuration file, or 2) you already have a SM_API environment variable so the one in .env isn't used. It's most probably number 1. There are a few other common cases; like your queue being handled/executed on another machine that you havn't updated or you're censoring things in your answers to the degree that we no longer understand the problem. |
@sisve, I also suspect that I have an old cached config file. But where it is located. Or how can I remove that? |
You can remove it with |
@sisve, I removed it. then create it again with |
@milon same as me |
In my case |
For me, |
just stop supervisorctl and start it again. It's happen due to cache of supervisorctl |
Another reason can be that your shell environment defines another env variable. Typically, I have Hope it helps someone one day. |
I had same problem when i changed alpine docker image to debian. On debian cron have specific behaviar https://manpages.debian.org/jessie/cron/cron.8.en.html |
Description:
I was trying to send an email from a job. It was actually calls an external API and I store the URL in
config/services.php
file like this-I also use this sm_api value from frontend like this
config('services.sm_api')
. There it works like a charm. but when I try to use the same value from a laravel job class, which actually dispatched from Redis queue server, the same function call returns null. I tried to log the wholeconfig()->all()
and it returns the predefined values, exceptsm_api
.It also shows mailgun's domain and secret value to null though I set it in the
.env
file. I also log theenv('SM_API')
value, and it works from the same job. So, the problem is I can bear withenv('SM_API')
from the job, but I can use mail, as the mailgun driver and key is null. But all this works fine from the frontend. I also tried it inphp artisan tinker
, and it works perfectly.I searched on google for this and found this. This issue suggest to use
php artisan config:cache
to resolve this. I tried this as well. But nothing happens.The text was updated successfully, but these errors were encountered: