Relative path not working in cron PHP script

Change the working directory to the running file path. Just use chdir(dirname(__FILE__)); include_once ‘../your_file_name.php’; //we can use relative path after changing directory in the running file. Then you won’t need to change all the relative paths to absolute paths in every page.

Daylight Savings and Cron

The answer would be dependent on the variant/extension of cron you are using. Some variants do not handle the Daylight Saving Time, leading to missing jobs and twice run of the job. If you are using the Paul Vixie cron, then it does handle the DST changes. As per the cron man page: cron checks … Read more

Run a mySQL query as a cron job?

I personally find it easier use MySQL event scheduler than cron. Enable it with SET GLOBAL event_scheduler = ON; and create an event like this: CREATE EVENT name_of_event ON SCHEDULE EVERY 1 DAY STARTS ‘2014-01-18 00:00:00′ DO DELETE FROM tbl_message WHERE DATEDIFF( NOW( ) , timestamp ) >=7; and that’s it. Read more about the … Read more

crontab PATH and USER

According to “man 5 crontab” you can set environment variables in your crontab, by writing them before your cron lines. There is also an example of a crontab so you just have to copy/paste it : $ man 5 crontab | grep -C5 PATH | tail # and files in /etc/cron.d. These files also have … Read more

Difference between Cron and Crontab?

cron is the general name for the service that runs scheduled actions. crond is the name of the daemon that runs in the background and reads crontab files. A crontab is a file containing jobs in the format minute hour day-of-month month day-of-week command crontabs are normally stored by the system in /var/spool/<username>/crontab. These files … Read more