我一直在运行一个简单的php脚本(它将运行时间记录在文本日志文件中)。从浏览器来看,它运行得很好,但当我在plesk 10.3.1面板中使用计划任务时,如下所示:
*/5 * * * * php /var/www/vhosts/eblogs.co.uk/httpdocs/frostbox/cron/crone_test.php
它确实在五分钟后运行,但没有在文本文件中写入任何内容,并通过电子邮件向我发送以下通知消息:
php [-f from_encoding] [-t to_encoding] [-s string] [files...]
php -l
php -r encoding_alias
-l,--list
lists all available encodings
-r,--resolve encoding_alias
resolve encoding to its (Encode) canonical name
-f,--from from_encoding
when omitted, the current locale will be used
-t,--to to_encoding
when omitted, the current locale will be used
-s,--string string
"string" will be the input instead of STDIN or files
The following are mainly of interest to Encode hackers:
-D,--debug show debug information
-C N | -c | -p check the validity of the input
-S,--scheme scheme use the scheme for conversion
我应该在下面的行中添加什么?
php /var/www/vhosts/eblogs.co.uk/httpdocs/frostbox/cron/crone_test.php
返回的文本是piconv的使用消息。这与脚本语言PHP完全无关。你可能想做的是以下之一:
备选方案1:使用PHP命令行解释器
您需要在系统上调用实际的php解释器。这可能是/usr/bin/php5
,所以您的crontab行看起来像
*/5 * * * * /usr/bin/php5 /var/www/vhosts/eblogs.co.uk/httpdocs/frostbox/cron/crone_test.php
但是,并不是每个安装程序都安装了这个命令行解释器。可能只安装了apache模块。
备选方案2:使用HTTP(S)请求
如果您无权安装命令行工具,请查看是否安装了wget或curl。如果是这样,您可以使用它们通过向web服务器发送请求来调用脚本。
使用wget:
/usr/bin/wget -O /dev/null 'http://eblogs.co.uk/crone_test.php'
-O /dev/null
告诉将脚本生成的网页保存在/dev/null
中。这是一个特殊的文件,基本上会立即忘记写入其中的所有数据。因此,此参数可以避免创建任何包含网页内容的新文件,并将其放在服务器的文件系统中。
使用卷曲:
/usr/bin/curl -o /dev/null 'http://eblogs.co.uk/crone_test.php'
-o /dev/null
在这里的功能与上面wget的大写为O的版本相同。
在php脚本顶部添加以下内容:
#!/usr/bin/php
<?php
your code here
?>
(假设php存在于/usr/bin)
希望能有所帮助!
您可以使用"curl"。。。像这样:
curl "http://eblogs.co.uk/crone_test.php"