Page 1 of 1

Detect whether PHP is CLI or Apache

Posted: Mon Dec 01, 2008 11:36 pm
by alex.barylski
I know it's probably obtainable with some weird checks...using phpinfo() for example but I'm curious incase there is an API which I have overlooked...

Is it possible to detemrine whether PHP instance running is invoked by Apache or CLI?

Will I have to detect this informaiton much like a browser is detected, by checking environment variables, etc.

Hopefully there is a simple API :D

Re: Detect whether PHP is CLI or Apache

Posted: Tue Dec 02, 2008 12:47 am
by Cirdan
There is an environment variable named SERVER_SOFTWARE, probably access it through $_SEVER[]

Re: Detect whether PHP is CLI or Apache

Posted: Tue Dec 02, 2008 1:35 am
by Christopher
$_SEVER["SERVER_SOFTWARE"] probably will not be defined in CLI -- along with many other values. I would check something like isset($_SERVER["SERVER_PROTOCOL"]) and equal "HTTP" to see if it's a webserver and isset($_SERVER["argc"]) to see if it's CLI.