Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron Job $_SERVER issue

Tags:

I want to run a cron job. My application is developed in PHP and Mysql.

In browser if i use $_SERVER[HTTP_HOST] in coding, it works fine. But if I use the same thing in cron job it is giving errors.

Can any body give suggestion to fix this?

like image 922
user1049997 Avatar asked Feb 03 '12 12:02

user1049997


People also ask

Why is cron job not working?

You might discover that your job works when run via the command line, but won't run via cron. This may be due to the location you're executing from or the PATH you're using. The use of relative paths is a common cause of cron issues. In cron, the PATH is set by default to /bin:/usr/bin .

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

How do you check if cron job is working or not?

Running the “systemctl” command along with the status flag will check the status of the Cron service as shown in the image below. If the status is “Active (Running)” then it will be confirmed that crontab is working perfectly well, otherwise not.

How do you prevent crond?

Stop a cron job You can stop a single cron job by removing its line from the crontab file. To do that, run the crontab -e command and then delete the line for the specific task. Alternatively, you can stop the cron job by commenting it out in the crontab file.


1 Answers

$_SERVER['HTTP_HOST'] is not populated when running it from a cronjob, the file is not accessed via HTTP.

You will either have to hardcode the Host or pass it via a command line argument and access it via the $_SERVER['argv'] array.

like image 159
TimWolla Avatar answered Nov 10 '22 14:11

TimWolla