我有一个PHP应用程序,当我从网页运行它时,但不是当我cron独立的php文件时

时间:2012-09-19 20:31:11

标签: php cron

我的问题非常疯狂。因为,我有一个完整的工作PHP脚本,当我使用此代码执行网页时运行..

<html>
<body>
<p>Hello</P>
<?php
$file1 = file_get_contents("http://services.runescape.com/m=itemdb_rs/api/graph/440.json");
$file2 = file_get_contents("http://services.runescape.com/m=itemdb_rs/api/graph            /434.json");
$file3 = file_get_contents("http://services.runescape.com/m=itemdb_rs/api/graph/10294.json");
$file4 = file_get_contents("http://services.runescape.com/m=itemdb_rs/api/graph/2621.json");
$file5 = file_get_contents("../json/440.json");
$file6 = file_get_contents("../json/434.json");
$file7 = file_get_contents("../json/10294.json");
$file8 = file_get_contents("../json/2621.json");
if(($file1 != $file5)or($file2 != $file6)or($file3 != $file7)or($file4 != $file8))
{








$my_t=getdate(date("U"));
$hour = $my_t[hours];
$setTime = 12;
$ending = " # ";
if($hour > $setTime){
$hour-=$setTime;
$ending = "PM";
}else{
$ending = "AM";
}

print($file);
print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]   $hour:$my_t[minutes] $ending");
 $to = "php.tester@mailinator.com";
 $subject = "Ge Has Updated";
 $body = "$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]     \n$hour:$my_t[minutes] $ending";
 if (mail($to, $subject, $body)) {
   echo("<p>Message successfully sent to ".$to." !</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }

copy("http://services.runescape.com/m=itemdb_rs/api/graph/440.json","../json/440.json");
copy("http://services.runescape.com/m=itemdb_rs/api/graph/434.json","../json/434.json");
copy("http://services.runescape.com/m=itemdb_rs/api/graph/10294.json","../json/10294.json");
copy("http://services.runescape.com/m=itemdb_rs/api/graph/2621.json","../json/2621.json");

 } 
?>
</body>
</html>

但是当我删除<?php.... ?>标签中的内容时......但我也复制了php标签。并保存为一个独立的PHP脚本,我使用Cron每五分钟运行一次。不起作用。有什么帮助吗?

PS。我试过手动编辑我的本地.json文件只是为了确保它不起作用。

编辑:我从<?php开始复制,以?>所有内容复制。包括标签。

2 个答案:

答案 0 :(得分:1)

脚本是否可执行。我也可能会将脚本本身的相对路径更改为绝对路径。

https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work

答案 1 :(得分:0)

如果没有<?php....?>标记,PHP脚本将无法运行。