tags:

views:

1240

answers:

2

When a script runs under Apache, I insert $_SERVER['SERVER_NAME'] value into an error reporting e-mail message.

However, if a Web script forks a "worker" job with nohup php ..., $_SERVER['SERVER_NAME'] appears to be empty there. Thus, if an error occurs, it's reported without a host name.

Can I reliably get the host name by means of PHP, without calling Unix hostname command?

+10  A: 

php_uname("n")

Prody
A: 

You can use _GLOBALS['MACHINENAME'] to obtain the information straight from the globals array.