Hi everyone,
i use file_get_contents/fopen in a bunch of snipets for interconecting sites. The problem is, that from time to time
one of the servers goes down. When this happens the file_get_contents will generate an error and the whole modx system
dies out. Is there a way to catch this error before it kills the site? I have tried replacing the error handle, use try...catch,
nothing works. When the file_get_contents returns an error, the page where the snippet is used doesn’t display any more, just a big
modx error. Till now i found no solution on google or anywhere. I’m using modx evolution. Help is appriciated ...
Thank you.
-
☆ A M B ☆
- 2,475 Posts
When file_get_contents() fails, you have to try using curl. It’s a lot more complicated, and it’s not always compiled into PHP with all the options you want or need, but it has much more robust handling for intermittent servers... and all servers are intermittent.
Would it work to use:
and examine $http_response_header before continuing?
$http_response_header should still be set even when file_get_contents() fails.
-
☆ A M B ☆
- 2,475 Posts
Exactly: using @ to suppress errors doesn’t make your script retry the problematic server, it just makes it fail silently. If you need to keep pounding a server until it yields the files/pages you want, you have to use CURL.