1

Im running PHP 5.4.

This is my setup:

../checker.php

../index.php

from conscript.php I use a cronjob to run it each 5 minutes or so but I want the echo of the cURL to display on index.php. How do I receive the echo at index.php?

It would also be possible to let cURL store the results from the checker.php in a file for ehm. results.php and let index.php grab/iframe from results.php but I have no idea how.

4

1 回答 1

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;
      }

?>

索引.php

<?
$file = "urlUpResults.txt";
echo "<h1>UpCheck results:<h1><br>" . file_get_contents($file);
?>
于 2013-09-28T20:08:36.493 回答