gethostbyaddr () communicates with the outside

【 Overview 】

On a system with PHP, the browser display is displayed for some reason There was a phenomenon that it became heavy.

In my research, when I looked at it with the linux netstat command, There was a lot of communication to port 53.

What? I thought, and after investigating various things, I found that the cause was gethostbyaddr ().

[Cause]

First of all, gethostbyaddr () is innocent. There was a problem with how to call.

It's a PHP source, it's written poorly, There was a place where I was looping in vain (a lot).

Because I was calling gethostbyaddr () in that loop I was getting a lot of DNS inquiries from the server.

After making a fix to reduce the number of calls The load on the server (network) is reduced, The browser display has become lighter.

[In the first place]

Does gethostbyaddr () communicate with the outside world? You might have thought, but if you ask, Because the host name is obtained from the IP address You're doing a reverse DNS lookup, right? I can imagine.

(You should really look at the source of gethostbyaddr () itself, I don't have that skill, and I'm sorry, but I'll leave it to you. )

For example, if this is mb_send_mail (), it will send an email, You'll think it's bad to loop.

But gethostbyaddr () is communicating behind the scenes I don't notice it easily. You might think it's just a conversion function. (Especially if you are a person who is not familiar with servers and infrastructure.)

[Summary]

Before modifying the PHP source, use the name server of the communication destination It's like doing a Dos attack. (I'm sorry.)

Like the number of times you call gethostbyaddr (), Don't call the same IP address over and over again I think it is also necessary to devise ways to cache the results.

However, there is no problem with using it normally. I was incredibly looping It just increased the network load.

Recommended Posts

gethostbyaddr () communicates with the outside
Insert the debugger with nose
Kill the process with sudo kill -9
Guess the password with klee
scraping the Nikkei 225 with playwright-python
Check the code with flake8
Calibrate the model with PyCaret
Call the API with python3.
Decrypt the QR code with CNN
Extract the xz file with python
Extract the maximum value with pandas.
Use the preview feature with aws-cli
Specifying the date with the Twitter API
The universe is dangerous with PyEphem
Pave the road with combinatorial optimization
Run the app with Flask + Heroku
Get the weather with Python requests
Get the weather with Python requests 2
Find the Levenshtein Distance with python
Explore the maze with reinforcement learning
Finding the simplest mistakes with OpenCV
Hit the Etherpad-lite API with Python
Install the Python plugin with Netbeans 8.0.2
Output the call graph with PyCallGraph
Install the data files with setup.py
Debug the script with Sakura Editor
I liked the tweet with python. ..
Using cgo with the go command
Master the type with Python [Python 3.9 compatible]
Hit the top command with htop
Try blurring the image with opencv2
Validate the learning model with Pylearn2
Open the file with the default app
Prepare the development environment with anyenv