"cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux

admin

Administrator
Staff member
My Wordpress installation on Azure App Service on Linux using a custom Docker container has very slow response times. Pages take around 20-40 seconds to load.

I have a troubleshooting plugin installed which indicates the problem is "cURL error 28: Resolving timed out after N milliseconds" when making requests to the following URLs

<ul>
<li><a href="https://api.wordpress.org/core/version-check/1.7/" rel="nofollow noreferrer">https://api.wordpress.org/core/version-check/1.7/</a></li>
<li><a href="http://api.wordpress.org/core/version-check/1.7/" rel="nofollow noreferrer">http://api.wordpress.org/core/version-check/1.7/</a></li>
<li><a href="https://api.wordpress.org/plugins/update-check/1.1/" rel="nofollow noreferrer">https://api.wordpress.org/plugins/update-check/1.1/</a></li>
<li><a href="http://api.wordpress.org/plugins/update-check/1.1/" rel="nofollow noreferrer">http://api.wordpress.org/plugins/update-check/1.1/</a></li>
<li><a href="https://api.wordpress.org/themes/update-check/1.1/" rel="nofollow noreferrer">https://api.wordpress.org/themes/update-check/1.1/</a></li>
<li><a href="http://api.wordpress.org/themes/update-check/1.1/" rel="nofollow noreferrer">http://api.wordpress.org/themes/update-check/1.1/</a></li>
</ul>

<a href=" " rel="nofollow noreferrer"><img src=" " alt="curl errors"></a>

cURL works fine on the scm-site command line. For example this works OK.

Code:
curl -X POST http://api.wordpress.org/core/version-check/1.7/

<strong>Edit</strong>
If i ssh into the container and run this php code, it works fine.

Code:
&lt;?php

$url = 'http://api.wordpress.org/core/version-check/1.7/';

$fields = array(
    'version' =&gt; urlencode('4.8.1'),
    'php' =&gt; urlencode('7.1.8'),
    'locale' =&gt; urlencode('fi'),
    'mysql' =&gt; urlencode('5.6.26.0'),
    'local_package' =&gt; urlencode('fi'),
    'blogs' =&gt; urlencode('1'),
    'users' =&gt; urlencode('4'),
    'multisite_enabled' =&gt; urlencode('0'),
    'initial_db_version' =&gt; urlencode('26691')
);

foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
rtrim($fields_string, '&amp;');

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

curl_exec($ch);

curl_close($ch);

It returns the following.

Code:
[email protected]:/home/site/wwwroot# php curl.php
{"offers":[{"response":"upgrade","download":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1.zip","locale":"en_US","packages":{"full":"http:\/\/downloads.wordpress.org\/release\/wordpres
s-4.8.1.zip","no_content":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1-no-content.zip","new_bundled":"http:\/\/downloads.wordpress.org\/release\/wordpress-4.8.1-new-bundled.zip","par
tial":false,"rollback":false},"current":"4.8.1","version":"4.8.1","php_version":"5.2.4","mysql_version":"5.0","new_bundled":"4.7","partial_version":false}],"translations":[]}

My Docker image uses php:7.1.8-apache.

Here is my Dockerfile.

Code:
FROM php:7.1.8-apache
EXPOSE 80 443 2222

RUN apt-get update -y &amp;&amp; apt-get install -y --no-install-recommends \
    ssl-cert \
    ca-certificates \
    apt-utils \
    vim \
    curl \
    mysql-client \
    openssh-server \
    libmcrypt-dev \
    libcurl4-gnutls-dev \
    libicu-dev \
&amp;&amp; docker-php-ext-install -j$(nproc) iconv \
mcrypt \
mysqli \
json \
mbstring \
curl \
intl \
&amp;&amp; echo "root:Docker!" | chpasswd \
&amp;&amp; ln -s /home/LogFiles /var/log/apache2

ENV APACHE_CONFDIR=/etc/apache2 \
APACHE_ENVVARS=/etc/apache2/envvars \
APACHE_LOCK_DIR=/var/lock/apache2 \
APACHE_LOG_DIR=/var/log/apache2 \
APACHE_RUN_DIR=/var/run/apache2 \
APACHE_PID_FILE=/var/run/apache2/apache2.pid \
APACHE_RUN_USER=www-data \
APACHE_RUN_GROUP=www-data

WORKDIR /usr/local
COPY config/wprun.sh config/wp-config.php /usr/local/
COPY config/sshd_config /etc/ssh/
COPY config/php.ini /usr/local/etc/php/


RUN chmod 755 wprun.sh &amp;&amp; \
rm -R /var/www/html &amp;&amp; \
a2enmod rewrite &amp;&amp; \
a2enmod expires &amp;&amp; \
a2enmod include &amp;&amp; \
sed -i "[email protected]/var/[email protected]/home/site/[email protected]" /etc/apache2/sites-enabled/000-default.conf &amp;&amp; \
sed -i "[email protected]/var/[email protected]/home/site/[email protected]" /etc/apache2/apache2.conf

CMD ["/bin/bash","wprun.sh"]

<strong>Edit 2</strong>
This <a href="https://github.com/docksal/docksal/issues/312" rel="nofollow noreferrer">GitHub issue</a> seems similar. There is a suggestion to use <a href="https://www.digitalocean.com/commun...-resolving-timed-out-after-10518-milliseconds" rel="nofollow noreferrer">OpenDNS resolvers</a>. Could this be a DNS issue? If so, then how does this work with Docker and Azure?

<strong>Edit 3</strong>
This seems to be a DNS issue. This is the resolv.conf file in Azure.

Code:
search reddog.microsoft.com
nameserver 127.0.0.11
options timeout:1 attempts:5 ndots:0

When i change nameserver to 8.8.8.8, pages load in one to two seconds. Also all the cURL errors go away.

If i understand correctly, <a href="https://docs.docker.com/engine/userguide/networking/configure-dns" rel="nofollow noreferrer">Docker mounts the host machine's resolv.conf file</a> and DNS settings should be set with Docker run command options. It's not recommended to change these files directly.

<blockquote>
The exact details of how Docker manages the DNS configurations inside
the container can change from one Docker version to the next. So you
should not assume the way the files such as /etc/hosts,
/etc/resolv.conf are managed inside the containers and leave the files
alone and use the following Docker options instead.
</blockquote>

However, it doesn't seem possible to set docker run parameters in Azure.