How do I find my server's IP address in PHP(CLI)

ChronoFish picture ChronoFish · Nov 29, 2009 · Viewed 58.8k times · Source

Aside from the obvious (localhost, 127.0.0.1) does PHP (command line interface!) have a mechanism for discovering the IP of the computer the script is running on?

$_SERVER[*] will not work as this is not a Web app - this is a command line script.

TIA

Answer

Nicolas Goy picture Nicolas Goy · Nov 29, 2009

You can get the hostname by using gethostname