A
A
Anton2017-03-13 18:43:42
PHP
Anton, 2017-03-13 18:43:42

How to catch 404 when requesting api?

Hello. I have a site that knocks on api to another site, I get a response from it with the help, file_get_contentsbut what if the server does not respond? How can I catch 404 and then perform some actions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2017-03-13
Reytarovsky @Antonchik

function get_contents() {
  file_get_contents("http://example.com");
  var_dump($http_response_header);
}

Better use cURL, it will be faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question