i am using file_get_contents to run a php script on my website that will export some data in a textfile. The php script "export.php" prints out "OK" when the job is done and "Error" if an error occures.
If i run export.php in my browser it will print "OK" if i run it by calling file_get_contents in another php script the result is empty. But export.php prints in any case "OK" or "Error".
This is my script that calls export.php:
$opts = array('http' =>
array(
'method' => 'GET',
'timeout' => 240
)
);
$context = stream_context_create($opts);
$url_pre = "http://";
$url = "127.0.0.1/export.php";
$html = @file_get_contents($url_pre.$url,false,$context);
if ($html === false){
$job_ok=false;
$result=error_get_last();
echo "Error: ".$result."<br />";
}else{
if (substr($html,0,2)=="OK"){
$job_ok=true;
$errurl = "";
$result="Job done";
echo "Job done: ".$result."<br />";
}else{
$job_ok=false;
$errurl = $url_pre.$url;
$result=$html;
echo "Error: ".$result."<br />";
}
}
echo "HTML: $html <br />";
The result of the script is:
Error:
If i open "http://127.0.0.1/export.php" in my browser i get:
OK
Maybe someone can help me!
Thanks!
@from@file_get_contentsto see if function is returning errors