Anil agrahari
Anil agrahari

Reputation: 340

run php file using crons jobs in centos

I have setup a cronjob in etc/crontab file as shown below

*/1 * * * * root /var/www/html/crons/check-solr.php

The above line runs a php script after every minute.

I have the stopped the cron using service crond stop and then again started the cron. But it did not run. The script is not running. please let me know if I am missing anything.

Regards Anil

Upvotes: 1

Views: 7735

Answers (3)

llanato
llanato

Reputation: 2491

Sometimes you might need to add the full path of PHP if PHP isn't part of the system path variables, something like so depending where PHP is on your system:

*/1 * * * * /usr/bin/php /var/www/html/crons/check-solr.php

Upvotes: 0

batfastad
batfastad

Reputation: 2013

Sorry for replying to such an old Q.
You can't (usually) run PHP scripts directly from the command line by just typing the path to the .php file.

You need to run the PHP executable then specify your .php file as the file to parse/run... http://www.php.net/manual/en/features.commandline.usage.php

*/1 * * * * php /var/www/html/crons/check-solr.php

That should do the trick.
I run PHP CLI scripts with cron all the time, I find it's often the easiest way to accomplish some tasks quickly and pretty portable.

Upvotes: 2

Kae Verens
Kae Verens

Reputation: 4079

in order for the script to run, it must have execute rights.

chmod +x /var/www/html/crons/check-solr.php

keep an eye on your logs in case there is an error

Upvotes: 3

Related Questions