[php-src] Issue #12673: Running `dns_get_record()` on localhost in Docker has an 8 second delay and then errors
| From: | hdodov | Date: | Wed, 15 Nov 2023 08:58:23 +0000 |
| Subject: | [php-src] Issue #12673: Running `dns_get_record()` on localhost in Docker has an 8 second delay and then errors | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245804@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12673
Author: hdodov
### Description
I'm running [the latest WordPress Docker
image](https://hub.docker.com/layers/library/wordpress/latest/images/sha256-76d0031ce9930987b40995908ce54f3e6b2297bc37c443e06b7b2ad1a2542343?context=explore)
on my macOS machine using the provided
docker-compose.yml in [its Docker hub
page](https://hub.docker.com/_/wordpress):
```yaml
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
```
Then, I put the following in /var/www/html/index.php:
```php
<?php var_dump(dns_get_record('localhost', DNS_CNAME));
```
When I open http://localhost:8080/, I get an 8 second delay
before receiving a result:
```
$ time curl localhost:8080
bool(false)
curl localhost:8080 0.01s user 0.01s system 0% cpu 8.023 total
```
…and in the logs, I have the following error:
```
wordpress-1 | [Wed Nov 15 08:21:56.524357 2023] [php:warn] [pid 97] [client 192.168.65.1:51109] PHP
Warning: dns_get_record(): A temporary server error occurred. in /var/www/html/index.php on line 1
wordpress-1 | 192.168.65.1 - - [15/Nov/2023:08:21:48 +0000] "GET / HTTP/1.1" 200 186
"-" "curl/8.1.2"
```
---
I'm not sure if this is a PHP issue, a Docker issue, or an OS issue, though.
I tested the same thing at home yesterday on my Windows PC and experienced slightly different
issues, although issues nonetheless. I ran PHP 8.1.10 **without Docker** (using XAMPP) and got a ~1
second delay with the following error:
```
Warning: dns_get_record(): DNS Query failed in C:\Projects\test\index.php on line 1
bool(false)
```
Then I ran this on my Windows PC **inside Docker**, although in a different Docker container running
PHP 8.1.18, and got the following result with absolutely no delay:
```php
array(1) {
[0]=>
array(5) {
["host"]=>
string(9) "localhost"
["class"]=>
string(2) "IN"
["ttl"]=>
int(0)
["type"]=>
string(5) "CNAME"
["target"]=>
string(9) "localhost"
}
}
```
Finally, on my macOS work machine, I got an 8 seconds delay again in another Docker WordPress
project using [this Bitnami
image](https://hub.docker.com/layers/bitnami/wordpress/6.2.0-debian-11-r14/images/sha256-1e636e1b9651af99d0fafd8da80f6c44dd744b7d722cf3e50394c7f12774a157?context=explore)
and PHP 8.1.18.
---
I realize that I'm testing different PHP versions, but I'm wondering if anyone else can
reproduce this. Here's a summation of my tests:
- PHP 8.0.30, macOS, with Docker: 8 seconds delay, "temporary server error occurred"
- PHP 8.1.10, Windows, without Docker: 1 second delay, "DNS Query failed"
- PHP 8.1.18, Windows, with Docker: no delay, everything works
- PHP 8.1.18, macOS, with Docker: 8 seconds delay, "temporary server error occurred"
In [the PHP changelog](https://www.php.net/ChangeLog-8.php), I can see a few changes regarding
dns_get_record(), but the latest one was in PHP 8.0.14, and all my tests were on newer
versions. More interestingly, the same PHP version (8.1.18) works inside Docker on Windows and
doesn't on macOS, again with Docker. Can anyone else reproduce this?
I stumbled upon this issue because [Wordfence](https://wordpress.org/plugins/wordfence/) has [this
exact line of
code](https://github.com/wordpress-premium/wordfence/blob/18621a3ccea9a61146598b1b062a844c008eab76/lib/wfUtils.php#L998)
in its source code, as I've [explained in this
post](https://dodov.dev/blog/debugging-wordpress-performance-issues-on-localhost).
### PHP Version
PHP 8.0.30
### Operating System
macOS Ventura 13.6.1 (22G313)