file_get_contents(): php_network_getaddresses: getaddrinfo failed

后端 未结 3 2424
青春惊慌失措
青春惊慌失措 2021-02-19 21:07

I\'m trying to update some values from one server to another server with a cron job. I use file_get_contents().

The strange thing is that this fails occasionally. One min

相关标签:
3条回答
  • 2021-02-19 21:41

    The name lookup appears to fail whilst running within a cron job sometimes. I've only seen it with names in /etc/hosts, but I haven't tested DNS names.

    I was seeing it with sending email and SMTP connection timeouts.

    I don't know the exact cause, but in my case I got my SMTP code to connect to 127.0.0.1 instead of localhost and the problem went away.

    0 讨论(0)
  • This is because of connection limits on 2nd server, and I believe that you have set short time intervals for the cron job. As you know, servers control consecutive connections from each IP. You may choose a longer time interval to resolve this problem.

    0 讨论(0)
  • 2021-02-19 21:55

    In my case, the trouble was that Apache get the DNS entries from /etc/resolv.conf when it starts. By the time I started my Apache, the network was not set yet. Restarting Apache (after networking is configured) solved the problem for me.

    I explained the case in more details on my blog post http://diogomelo.net/blog/16/Warning-file_get_contents-php_network_getaddresses-getaddrinfo-failed-No-address-associated-with-hostname

    0 讨论(0)
提交回复
热议问题