Will the PHP function file_get_contents connect to subsequent IPs in the resolving list?

Question:

If one domain name resolves to the IP list, will the PHP function file_get_contents() connect to the next IP if the first one is not available?

If the behavior of the function is consistent with the standard, then please refer to it.

Answer:

No, it will not. Established experimentally.

Reasoning:

adding multiple A records for the same name is an implementation of the simplest round-robin balancing mechanism. One of the drawbacks of which is that if one node is unavailable, the requests sent to it will not be executed and this will lead to partial unavailability of the resource. those. the algorithm is suitable for load balancing, but not for increasing availability. However, this does not mean that a specific client (php) cannot implement its own mechanism for bypassing alternative addresses.

Search:

The php documentation doesn't say anything about this. the documentation has a gethostbynamel() function that returns a list, which means it can be implemented in php. I also found nothing in the RFC standards with a cursory search. I also looked in the C sources from php, but I could not find anything similar to the implementation of the workaround. since all this does not mean that it does not exist – I decided to do an experiment

Experiment

added to one normal record two not normal ones (A 1.1.1.1 and A 8.8.8.8). Then I implemented a call to file_get_contents, after which I made sure that php version 7.0.15 perfectly receives content only for every 3rd request. If there was an option that changed this behavior, it would be described here

Implementation possible

I believe that the author of the question can implement his own function wrapper with the behavior he needs, using the IP addresses obtained from gethostbynamel instead of the host,

Scroll to Top