0

My friend gave me free hosting, and I am doing CRON job on his server. But he said, your CRON job is affecting my server. Just stop the output and everything will be fine.

This is my JSON code

$response = file_get_contents("https://api.themoviedb.org/3/movie/".$requestsDone."?api_key=522cec782xxxx6f6d1e0c834a");
if ($response != FALSE) {
$response = json_decode($response, true);
}

So, i removed all echo lines. But, I still get this error echo'ed.

Warning: file_get_contents(https://api.themoviedb.org/3/movie/39740?api_key=522cec78237f49axxxxxxxxxxx6d1e0c834a): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

I am opening Thousands of URL's, and some URL contain this line

{"status_code":34,"status_message":"The resource you requested could not be found."}

Just this line, nothing more.

So, the page is still opening, why it gives that error? How to stop that?

Or just anyway to stop PHP echoing the error on the page (just for this file, not for whole website).

Toby
  • 717
  • 2
  • 8
  • 19
  • 1
    Oh, I found the answer earlier, but i made a typo mistake. In order to stop PHP showing error, type this line at the beginning `error_reporting(E_ERROR);` – Toby Jul 08 '17 at 13:46
  • @RajdeepPaul Do ***NOT*** turn off error reporting, this is bad advise. Please do not follow it. Error reporting is there for a reason and turning it off with add many hours to your workload when you find some other errors in your code. By changing your error output to simply `E_ERROR` this is a better solution. – Martin Jul 08 '17 at 13:52
  • You mean `error_reporting(E_ERROR);` @Martin. I checked my whole code, and this is the only error, I can possibly get, and it's nothing. So it's cool right? I do not want to harm my friends server – Toby Jul 08 '17 at 13:55
  • duplicate for https://stackoverflow.com/questions/44986113/how-to-stop-the-error-message-if-json-file-failed-to-open-stream/44986989#44986989 – Ivo P Jul 08 '17 at 13:57
  • @Martin Yes, I'm aware of the consequences of turning error reporting off, that's why the comment, not an answer. I was about to edit my comment explaining the possible downside of turning error reporting off. Never mind, I deleted it altogether since it might mislead future visitors of SO. However, `E_ERROR` won't do any good, it's going to print the messages anyway. – Rajdeep Paul Jul 08 '17 at 13:58
  • @RajdeepPaul I was only running from the commet made by Toby that he had it working with `E_ERROR`. It's better to clarify expected errors than to block all errors. – Martin Jul 08 '17 at 13:59

1 Answers1

1

first check this condition if($content === FALSE) { } .

if still you get same problem use @ in front of the call to file_get_contents(): $content = @file_get_contents($site);

sekaraja
  • 177
  • 1
  • 1
  • 8