Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


  • cURL 7.32.0
  • Apache 2.2.25
  • PHP 5.5.4

Whenever I attempt to:

$ch = curl_init('');


within PHP, I get:

Could not resolve host:

If I change to curl_init('') (resolved, the script executes.

Though, running curl in CLI, I get a 302 Moved HTML page, due to redirect to localized site (*.lv), but still, that means that cURL executed successfully.

I have seen multiple similar questions (not on SE though), most of them saying that Apache is started either before or concurrently with Network Manager, hence not receiving DNS information. Most of the questions have answers explaining, that the issue can be temporarily resolved/debugged by explicitly stopping, then starting the Apache daemon (instead of restart/graceful-restart).

fsockopen, file_get_contents works flawlessly, though.

My Apache virtual host:

<VirtualHost *.777>
    ServerName localhost

    DocumentRoot "/srv/stone/public"

    ErrorLog "/srv/stone/app/storage/logs/apache-errors.log"
    CustomLog "/srv/stone/app/storage/logs/apache-custom.log" common

    <Directory /srv/stone/public>
        php_admin_value open_basedir /

        # Pretty URL rewrites, better not to rely on .htaccess
        <IfModule mod_rewrite.c>
            Options -MultiViews

            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]

        # Prevent further overrides
        AllowOverride None

        Order allow,deny
        Allow from all

And global config just has a specific entry for Listen 777.

This and this, both lead to DNS problem, so, I think I may have problems with it too, plus, it clearly looks like it.

I've given a shot by changing virtual host entries to and other configurations to no avail.

How do I fix the issue?

share|improve this question
If you try to put in your /etc/hosts you should be able to confirm that this is a DNS issue. It's a bit strange that your CLI command manage to perform the lookup though. FYI, the code works on my Apache installation. – Qben Sep 25 '13 at 11:20
Adding it to hosts did make the script work. – joltmode Sep 25 '13 at 11:33
up vote 1 down vote accepted

It appears that the problem was with my /etc/resolv.conf.

I had set up a custom network connection manager, that executed an external command to set up nameservers from a specific configuration file. The setup would simply erase the contents of /etc/resolv.conf, append with new info and then start the network interface, set it's parameters (IP, Mask, Cast, Gate) and voila.

Apparently that screwed up something. I guess I will have to look for different Before/After targets and write a custom resolv.conf updater.

I did leave resolv.conf static now, and that seems to fix the issue.

In the end, clearly this was a DNS problem. Thankfully, it's fixed.

share|improve this answer

Have you tried the CURL_IPRESOLVE_V4 option?

$ch = curl_init('');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HEADER, true);

And what is the output of the headers if you use the CURLOPT_HEADER option?

share|improve this answer
FYI: curl_setopt has to come before curl_exec, but, It doesn't even get that far to gather headers, it simply cannot connect. Dies all the time with Could not resolve host. I did already try the IPRESOLVE_V4 option before, doesn't work. Did it now again, nothing... – joltmode Sep 25 '13 at 9:05
Oops, yes. That was a type. Had a working code here and it went wrong with copy and paste. – Rik Sep 25 '13 at 9:07
Why did you try This is not the same as your Here the curl_info gives as primary_ip on could you try curl_init('')? What result do you get? Here goes right to without giving a page is moved. Did you try curl and curl in CLI? (this may all be a localisation issue but you can try) – Rik Sep 25 '13 at 10:11
Haha, both with curl -v and curl -v in CLI i get a 200 OK. With curl i get a 302 Found. Same with Curl in PHP. ping gives me – Rik Sep 25 '13 at 10:28
That doesn't change the fact that I have a problem with DNS'es related to Apache, mod_php and curl on the machine. – joltmode Sep 25 '13 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .