I have a strange error in my cron job. At the beginning while I am running the cron job its working fine. At that time I am define the variables normally. Like, $ck_host='abc';
. But now I change the code and access the same variable from the .env file of laravel. Like, $ck_host=$_ENV['CK_HOST'];
. When I am running in my browser it works fine. But in the cron job, it says undefined index: CK_HOST. I have attach the image of the log.
Note:
- I am using vlucas/phpdotenv for access env file.
- All the crons are not in Laravel. There are some in core PHP. The problem come in core PHP.
- Post an issue in github. But did not understand the answer.
I Think:
The problem is where I call the .env file in the code. This corn vendor is not able to use the function.
$dotenv = new Dotenv\Dotenv($doc_root);
$dotenv->load();
$doc_root
contain the path of the env file. Please note once again, all the files are working in the browser but when I run the cron I am writing a log file also. The error come there.
Please help me. Or tell me how will I use .env file without any vendor of laravel.
Thanks in advance for help.