开发者

PHP script in /etc/cron.weekly

开发者 https://www.devze.com 2023-02-10 00:53 出处:网络
I ha开发者_开发百科ve a php script in my website folder that needs to be executed weekly. I am on debian 6 (root).

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 ?

I mean which kind of file should I copy in /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
0

精彩评论

暂无评论...
验证码 换一张
取 消