0

Very short version: Is there a list of possible errors thrown by file_get_contents()?

I have a PHP application that downloads a lot of files over HTTP using file_get_contents(). Sometimes errors occur and I need a tidy way of handling different errors (e.g. I might like to pause and try again, or make a change to the database, or simply log the error and move on). I had a look around but was unable to find a list of all possible errors, does such a thing exist?

Edit:
I neglected to mention I am currently converting errors to exceptions. My error messages say things like "Failed to open stream: HTTP request failed!". I would rather not add code to handle errors in a piecemeal fashion.

Edit: Some examples of the error messages I am currently seeing:
file_get_contents(): SSL: An existing connection was forcibly closed by the remote host file_get_contents(_URL_): Failed to open stream: HTTP request failed! file_get_contents(_URL_): Failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

Testic
  • 157
  • 1
  • 1
  • 9
  • 1
    `file_get_contents()` doesn't throw any exceptions. If you want to be able to react differently to things like HTTP response status, take a look at something like [Guzzle](https://github.com/guzzle/guzzle), which issues [various exceptions](https://docs.guzzlephp.org/en/stable/quickstart.html#exceptions) that you can catch. – Alex Howansky Feb 03 '23 at 19:23
  • Quite right, I failed to mention that I am converting errors to exceptions, my question has been edited for clarification. Meanwhile I am looking at Guzzle. – Testic Feb 03 '23 at 19:29
  • I'd be surprised if the vast majority of errors you receive from `file_get_contents` are solvable in the first place, to the point that I don't know if there's a reason to do much beyond log it generally? Even with a high-level thing like Guzzle, you pretty much either get a response or you don't. Using [`ignore_errors`](https://stackoverflow.com/a/11479968/231316) and relying more on HTTP status codes might be helpful, too. – Chris Haas Feb 03 '23 at 19:37

0 Answers0