Posted on February 14, 2019 at 10:52 pm
Sometimes gethostbyname() can take up to 5 seconds and more to complete.
Here are two smart tricks to make it faster:
// Set timeout and retries to 1 to have a max execution time of 1 second for the DNS lookup putenv('RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1'); // Make sure the domain ends in a dot to prevent DNS recursion lookups $ip = @gethostbyname("google.com.");
Thansk to Dennis for these awesome tips:
It works also with gethostbyaddr().
Updated on April 16, 2019 at 11:36 pm
- PHP Generate Secure Random Passwords
- Google Cloud SQL and Public IP Address Security
- How to use Highlight.js to highlight code
- Nginx HTTP to HTTPS and non-www to www behind Google Load Balancer
- Quota 'IN_USE_ADDRESSES' exceeded. Limit: 8.0 in region
- Only allow Google Load Balancer traffic (Firewall Rules)
- Lost connection during Debian apt-get upgrade
- Bootstrap 3 Navbar with Logo Image
- PHP StrToTime() Returns Incorrect Timestamp '-1 MONTH'
- PHP Correctly Get Last 12 Months (Month per Month)
- Nginx Redirect From a Website to Another Website
- PHP Multi-cURL to Run Parallel cURL Requests (Example)
- Let's Encrypt on Nginx and SSL Grade A+
- Vertically align Facebook and Twitter share buttons
- Download Windows 10 ISO without Media Creation Tool
- DEB.SURY.ORG Updated the Signing Key (March 2019)