J. Scott Elblein
J. Scott Elblein

Reputation: 4273

Which is faster for resolving an IP?

Has anyone done any testing to see which is faster/more efficient/better for resolving an IP address in a PHP script?

This

exec('host '. $_SERVER['REMOTE_ADDR']);

or this

gethostbyaddr($_SERVER['REMOTE_ADDR']);

Upvotes: 0

Views: 124

Answers (2)

paxdiablo
paxdiablo

Reputation: 882028

You should try it yourself but I would think the cost of starting a whole new process would be more than just calling the gethostbyaddr function. Going the external executable route also makes you dependent on a lot of other things, like the OS, your path being set up correctly, the possibility that the output of host may change, and so on.

Optimisation mantra number 1 is measure, don't guess! Number 2 is only optimise if you have established it's a bottleneck, so make sure it's actually causing a problem before you waste time trying to fix something irrelevant.

Upvotes: 0

xdazz
xdazz

Reputation: 160883

If there is a native function, then you should use it instead of using an external command.

Using a external command make your program OS dependent.

Upvotes: 1

Related Questions