What could be causing the "gethostbyname failed" error in the PHP script?
The "gethostbyname failed" error in a PHP script could be caused by a DNS resolution issue, where the hostname cannot be resolved to an IP address. This could be due to network configuration problems, incorrect hostname, or DNS server issues. To solve this error, you can try using the `gethostbyname()` function with error handling to catch any failures and handle them appropriately.
$hostname = 'example.com';
$ip = gethostbyname($hostname);
if ($ip === $hostname) {
echo "Failed to resolve hostname";
} else {
echo "IP address for $hostname is: $ip";
}