-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Description
I'm running the latest WordPress Docker image on my macOS machine using the provided docker-compose.yml
in its Docker hub page:
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 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:
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 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, 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 has this exact line of code in its source code, as I've explained in this post.
PHP Version
PHP 8.0.30
Operating System
macOS Ventura 13.6.1 (22G313)