0

我正在使用我的 cpanel 来启动一个 cron 操作,即每分钟打开一个文件并写一个 Hello。

但这项任务行不通。

这是我的代码:

<?php
header("Location: http://www.google.com");
$handle = fopen("passes.txt", "a");
fwrite($handle, "Hello");  
fwrite($handle, "\n");
fclose($handle);
exit;
?>

当我尝试直接在浏览器中使用脚本时,它工作正常,但 cron 作业根本不起作用。

我已使用此命令启动脚本:

* * * * * * http://www.mysite.com/myfile/write.php

.

EDIT:

你所有的commands都不为我工作。

Cron tasks在我的cpanel.

4

4 回答 4

2

你可以通过两种方式做到这一点

如果您的系统上有 wget:

1:* * * * * * wget -O /dev/null http://www.mysite.com/myfile/write.php

别的:

2: * * * * * * /path/to/your/php/bin/php /path/to/myfile/write.php

于 2011-02-01T20:05:57.967 回答
2

要每分钟运行一次此 cron,您必须使用如下内容:
*/1 * * * * wget http://www.mysite.com/myfile/write.php

* * * * * wget http://www. mysite.com/myfile/write.php

于 2011-02-01T20:07:29.857 回答
0

您需要通过 wget 发送请求,以模拟浏览器请求:

* * * * * * wget -q http://www.mysite.com/myfile/write.php 
于 2011-02-01T20:06:24.710 回答
0

您的命令不是可以在 shell 中运行的命令。它应该是

php /var/www/yoursitePath/yourFile/write.php

或者

curl http://www.mysite.com/myfile/write.php

我不知道header应该在脚本中为您做什么,但在这样调用时看不到任何效果

于 2011-02-01T20:06:27.153 回答