I ha开发者_开发百科ve a php script in my website folder that needs to be executed weekly.
I am on debian 6 (root).
How can I run this php script (in cli) weekly wihtout using crontab
?
/etc/cron.weekly
to run my php file?Just use an executable PHP script with a "shebang" line:
#!/usr/bin/php
<?php
// Your PHP code goes here
echo "Hello World!";
?>
Make it executable:
$ chmod +x myscript.php
Test it:
$ ./myscript.php
Hello World!
The "shebang" (#!) tells the shell that this script is to be executed with PHP, found in /usr/bin/php
.
Alternatively, you could write a small shell script that invokes the PHP interpreter with your PHP script:
#!/bin/bash
/usr/bin/php -f /path/to/script.php
精彩评论