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
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
Share on other sites

http:// is not a path. Its a url. If you want to execute your script via apache you will need to use something like wget to call them. Otherwise, you'll want to set them up as cli scripts.

 

I think my previous post explains things pretty well.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.