我需要直接从Web服务器执行每日下载,然后我想激活服务器支持的cron功能。我把一个脚本放在php中,所以
<?php
$file = file_get_contents('http://www.example.com/donwload.txt');
?>
当我调用脚本进行测试时,我希望在文件夹中找到&#39;脚本,甚至是下载的文件,但不浪费任何东西,显然我错了,Aas我能做到吗?
答案 0 :(得分:0)
有人问同样的事情here,所以我的建议是
如果您使用的是PHP,则可以创建一个函数并通过CLI调用。然后你需要在crontab中添加它。
示例index.php
<?php
//Get the data from the mysql table and process
$ data = getDataFromTable();
if ($data['user_defined_time'] == date('H') // Current Hour
echo "Foo Bar"; //send email
?>
要测试此功能,请打开终端并运行命令php -f index.php
将此添加到crontab。在终端中键入crontab -e并将该行编辑为:
每小时运行一次脚本
0 * * * * php -f /location/of/php/file/index.php