Wordfence takes 30 secs to load on localhost when using custom domain name
-
I think I’ve found a bug in the wfUtils::serverIPs() function that causes Wordfence to make each request take 30+ seconds to execute.
The issue only affects local installations with custom domain names that don’t contain a dot, such as “mytestsite” (but it doesn’t happen if you use “mytestsite.test” or “localhost”).
Steps to reproduce:
1) Install WordPress + Wordfence
2) Configure the site to use a custom domain name WITHOUT a dot, such as “mytestsite”
3) Open the frontpage of the websiteResult: The request takes 30+ seconds to load
Expected result: The request should take less than a second.
My environment: Apache 2.4 running PHP 7.4 on a MacBook Pro with a M1 Pro chip.
The problem is the following line in wfUtils::serverIPs():
$aRaw = @dns_get_record($host, DNS_A);When used with a value such as “mytestsite” on my machine, it takes 30 seconds.
To fix this problem, you can simply add a “.” after the hostname. This also works for all other requests, such as “realdomain.com” (i.e. looking up “realdomain.com.”):
$aRaw = @dns_get_record($host . ‘.’, DNS_A);Links to two resources where I found out that adding the dot is valid notation and that it solves timeouts/slow lookups when specifying a non-existent domain name:
https://www.php.net/manual/en/function.dns-get-record.php#121278
https://stackoverflow.com/a/14077874PS: The obvious workaround is to disable Wordfence when doing local development, which I’ve already done. But I thought you might want to know about this issue nonetheless.
Thanks in advance.
- The topic ‘Wordfence takes 30 secs to load on localhost when using custom domain name’ is closed to new replies.