Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron job is not working properly in cpanel

Tags:

php

cron

cpanel

I have setup cron job, it is working properly, however when i directly runs the php file(from the path/url) it successfully runs, but from cron its not. However i set another very simple file to make sure my cron command/path is set correctly i created another file and used simple php mail function and its is running successfully. Kindly suggest me the possible areas to look into it. (I am using Cpanel)

like image 772
Manoj Avatar asked Oct 23 '12 12:10

Manoj


People also ask

How do I set cron jobs in cPanel?

In cPanel, select Cron Jobs in the Advanced section of the Main Page menu. You will find a table for adding new scripts and setting their time intervals. To simplify configuration, we include a drop-down menu with common settings such as Once Per Week or Once Per Month.

Why is my cron job not running?

If you are still suspecting a problem with the cron job, then there are normally 3 possibilities why it might not be running: The cron daemon (the system process that runs cron jobs) could not run the script or was unable to send an email There were issues with the mail server mailing the output or the email was lost

How do I know if a cron job has sent an email?

You may also need to go through the mail server log to double-check if there was an attempt to send an email after the completion of the cron job. Remember that the designated email address is set near the top of the cron job page in cPanel. You can use the email address to isolate the mail attempts in the mail server log.

How do I edit or delete a cron job?

When your cron job has been set up, you will see a success message. Scroll down to the “Current Cron Jobs” section. Click the “Edit” or “Delete” link. “Edit” will bring up the cron job settings. Make any necessary changes and click the “Edit Line” button. “Delete” will open a delete dialog.


1 Answers

Instead of putting in cronjob command like

php -f /path_to_script/script.php 

put command like this:

curl http://domain.com/yourscript.php

if you want to suppress output you can add > /dev/null at the end.

So full command would be:

curl http://domain.com/yourscript.php > /dev/null

Hope this helps!

like image 199
alan978 Avatar answered Sep 21 '22 15:09

alan978