If one domain name resolves to an 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 this link.

  • 2
    If I correctly understood that the domain name resolves the dns server with ip and not the browser function, etc. so where does file_get_contents ()? - Naumov
  • if dns is configured correctly then yes) And since file_get_contents () has nothing to do with it. - Fəqan Çələbizadə

1 answer 1

No, it will not. It is established experimentally.

Reasoning:

adding several A records for one name is an implementation of the simplest round-robin balancing mechanism. One of the drawbacks of which it is believed that when one node is unavailable - the requests sent to it will not be executed and this will lead to a partial inaccessibility of the resource. those. The algorithm is suitable for load sharing, but not for increased availability. However, this does not mean that a specific client (php) cannot implement its own alternative address crawl mechanism.

Search:

The php documentation says nothing about this. in the documentation there is a gethostbynamel() function that returns a list, which means it can be implemented in php. I didn’t find anything in the RFC standards in a quick search either. I also searched for C sources from php, but I didn’t find anything similar to the circumvention implementation. because All this does not mean that it is not - decided to do an experiment

Experiment

I added two not normal ones to one normal record (A 1.1.1.1 and A 8.8.8.8). Then I implemented the 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 changes this behavior, it would be described here ...

Implementation is possible

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