Jump to content

PHP Scripts Cron Jobs


topflight

Recommended Posts

If the script you want executed is a php script it should contain a shebang line on the very first line. This lets the shell know what program should execute your script. eg;

 

#/usr/bin/php
<?php

// some php script

?>

 

You can now simply put;

 

10 * * * * /path/to/your/script.php

 

in your crontab. Otherwise, without the shebang, you need to actually specify what program to use to execute your script within the crontab entry;

 

10 * * * * /usr/bin/php /path/to/your/script.php

I am still confused, do I need to add a certain piece of code to the file I want to be executed?

 

I think your confusion here stems from the fact that you're only used to seeing PHP run on the web. PHP is a scripting language just like any other. If you stick it in a file and mark it executable you can pass it to the PHP CLI interpreter instead of having it called by apache or whatever webserver you're using. The procedure for setting up the cron job is exactly the same whether it's a shell script, python script, perl script, PHP script, or any other executable.

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.