One thing can be checked if the user running the PHP script has read access to below file. /etc/resolv.conf
If not, changing the permission as below can fix the domain name resolution issue.
chmod 644 /etc/resolv.conf