Web Hosting Talk







View Full Version : Cron job question


okok
07-19-2002, 10:16 AM
Hi.

Is it possible to run a PHP script using Cron Job (in Cpanel)?

I have never used such tools, so if there is a way, please tell me how excaly this should be done.

Thanks!

Andyc
07-19-2002, 10:18 AM
Yes there is. Look in the CPanel menu for 'Cron Jobs'. This link takes you to a page to input the schedule and the command you wish to run.

ho247
07-19-2002, 10:27 AM
It's definitely possible to run PHP scripts via cron, you just need to get cron to call the webpage. The command that I use on one of my servers (which doesn't have CPanel on it) is:

/usr/bin/lynx -source "http://www.domain.com/yourScript.php"I've just tested this command on a CPanel server via SSH and I can confirm that it works. Take a look at the manual as to how to use the Cron Jobs section of CPanel and then enter the above text as a command in a cron job entry. Remember to change the URL to point to your script.

Alan

Blieb
07-19-2002, 01:34 PM
Locate your PHP location. Use that as the shebang line ...
(whereis php) ...

#!/usr/local/bin/php -q
<?php
CODE
?>



When you call the cron ... do:

php -f /path/file.php

If you are using a modular script, you do NOT need the shebang (#) line in each file, only the one the cron hits.

RackNine
07-19-2002, 02:05 PM
/usr/bin/lynx -source "http://www.domain.com/yourScript.php"

I'd very-very much recommend against this. If you run alot of crons with the added overhead of lynx and apache it can get ugly.

Blieb offers the best solution, run through the shell. Only PHP is loaded plus you can run the script under privileges of Cron.

Sincerely,

-Matt

okok
07-19-2002, 04:01 PM
Thank you all!

I have two questions:

Would there be anything bad in using ho247's way, if I need to run just relatively small scripts, one or two, once or twice a day?

And regarding Blieb's way (excuse my absolute lack of knowlegde) -- is the intention in the first part that I should simply create a file in this format :

#!/usr/local/bin/php -q
<?php
CODE
?>

with the script I want to run?

Thanks again

ho247
07-19-2002, 04:08 PM
I'd very-very much recommend against this. If you run alot of crons with the added overhead of lynx and apache it can get ugly.I've been using it on my server for many years now and I've not noticed any high load averages or anything. I've got about 20 odd of these cron commands and it's running fine.

Would there be anything bad in using ho247's way, if I need to run just relatively small scripts, one or two, once or twice a day?I don't see any problems with using my method for small scripts. But I'll leave this for someone else to comment on, Matt?

Alan

Janet
07-19-2002, 04:19 PM
Lynx works well...just make sure that you use the proper command switches to exit lynx and dump the contents into /dev/null after you touch the page. Otherwise, it'll get ugly.

ohz
07-19-2002, 05:15 PM
use

GET http://www.domain.com/script.php >/dev/null

apollo
07-20-2002, 12:51 PM
you can install php as a binary (like a command you can run in bash/shell. ) and then you can run it from the cron.

ps. the above methods with using Lynx or script that opens socket to port 80 (www server) is fine, unless your apache web server is down.