RHEL6 PHP curl fails if network started after apache starts
I do development on my RHEL6 laptop with a wireless device. The wireless network does not start until I log into the GDM session. This means apache starts before the network starts. Anyway, I find that PHP curl calls do not work unless apache is restarted. The curl requests fail to do work due to inability of curl to resolve hostnames. This simple request will fail unless apache is restarted:
<?php
$ch = curl_init("http://www.redhat.com/");
$fp = fopen("index.html", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
if ($response === false) { echo 'failed!'; }
curl_close($ch);
fclose($fp);
?>
Anybody have ideas on this?
Responses
Daryl,
It looks like libcurl has a DNS cache for each process. So libcurl is caching the DNS failures for the apache process. Restarting apache under a new process ID clears the cache.
I was looking at http://curl.haxx.se/mail/lib-2002-01/0076.html.
While it's not a solution (I couldn't find any information on altering or disabling this with libcurl), I do hope that it helps.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
