Jump to content

PHP cron jobs


gerkintrigg

Recommended Posts

Hi.

I've managed to create a cron job to execute a perl cgi script on one server, but I'm now using a different server (they have cron too though) I wondered whether I'm able to do the same thing with a PHP script (for automatic newsletters... membership renewal notifications - that kind of thing.)

 

If so... is it the same process? because it doesn't work when I set it... not only does it not do what the script should do, it also doesn't email me to say whether the cron has executed successfully or not.

 

I wasn't sure whether it might be the fact that it's a PHP script or the different server that might be causing the problem.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/77438-php-cron-jobs/
Share on other sites

Cron is simply a task schedualer. Cron itself will not email you when it runs, alot of people get used to this feature through some control panel and assume its cron itself that send the email. Not so.

 

Anyway, we need some details. How have you setup this cron job? Via crontab -e ? (ie; the command line), and if so, what does your crontab look like? Or, through some control panel? And even then, can we see the line that executes your script?

 

Are you trying to execute a cli (command line interface) php script or do you expect it to run like a script called vai apache?

 

The difference being the former will need a shebang line... eg;

 

#!/usr/bin/php

 

at the top, or will need to be called with the full path to the php executable within the crontab line... eg;

 

/usr/bin/php /full/path/to/your/script.php

 

The later will need to make a web request via cron. (Usually done with wget or curl) eg;

 

/usr/bin/wget http://yourdomain.com/crons/script.php

 

Also note that any filepaths used within your script will need to be absolute because cron has a very limited environment.

Link to comment
https://forums.phpfreaks.com/topic/77438-php-cron-jobs/#findComment-392048
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.