Category:

__Can you use CRON to run PHP files?__

Yes you can.

Firstly you need to add a line to your PHP script.
It has to be the first line of your script and must contain the server’s PHP executable location:

#/usr/bin/php -q

Please check with support where your php binary is located.

The -q flag suppresses HTTP header output. As long as your script itself does not send anything to stdout, -q will prevent cron from sending you an email every time the script runs. For example, print and echo send to stdout. Avoid using these functions if you want to prevent cron from sending you email.

After that let’s add the necessary command to our crontab. This can be done vi plesk, or command line if you have access, make sure the command running section is like below:

5 * * * * php /full/path/to/your/php/script.php

Be sure your “script.php” has the necessary permissions to be executable (“chmod 755 script.php”).

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.