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 ().
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.
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.)
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