cURL从另一页显示

时间:2013-09-28 18:26:30

标签: php curl cron

我正在运行PHP 5.4。

这是我的设置:

../ checker.php

../的index.php

来自conscript.php的

我使用cronjob每5分钟左右运行一次,但我希望cURL的echo能显示在index.php上。我如何在index.php上收到回声?

也可以让cURL将checker.php的结果存储在ehm的文件中。 results.php并让index.php从results.php获取/ iframe,但我不知道如何。

1 个答案:

答案 0 :(得分:0)

<强> cronCheckUrls.php

<?
//Set name of text file
$file = "urlUpResults.txt";

//Create blank file/delete contents of existing file before run rest of script
file_put_contents($file, " ");

//Build array of sites to check
$sitesArray = array("http://www.minecraft.net", "http://www.4stats.tk", "http://www.google.com", "http://www.stackoverflow.com", "http://www.brokentestwebsite.com");


foreach ($sitesArray as $value) { 
if (TPBUC($value))
    $upStatus = "<p>" . $value . " is up.</p>";
 else
    $upStatus = "<p>" . $value . " is down.</p>";
    file_put_contents($file, $upStatus, FILE_APPEND);
}


//cURL function

        function TPBUC($url){
             $agent = "Mozilla/5.0 (compatible; TPBUC/1.0;)";$ch=curl_init();
             curl_setopt ($ch, CURLOPT_URL,$url );
             curl_setopt($ch, CURLOPT_USERAGENT, $agent);
             curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt ($ch,CURLOPT_VERBOSE,false);
             curl_setopt($ch, CURLOPT_TIMEOUT, 5);
             curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
             curl_setopt($ch,CURLOPT_SSLVERSION,3);
             curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
             $page=curl_exec($ch);
             $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             curl_close($ch);
             if($httpcode>=200 && $httpcode<400) return true;
             else return false;
      }

?>

<强>的index.php

<?
$file = "urlUpResults.txt";
echo "<h1>UpCheck results:<h1><br>" . file_get_contents($file);
?>