Methods to determine if PHP is running from a shell or within apache? [duplicate]
Possible Duplicate:
How to differentiate between http and cli requests? Which method to detect run mode of php script is more reliable?
What's the best method to determine if php is running from a shell (cron or otherwise) or running under apache?
you might find this useful: http://php.net/manual/en/function.php-sapi-name.php
echo php_sapi_name()==="apache2handler"; //running under apache?
http://sandbox.phpcode.eu/g/5f9d5
See marcelog's answer if you need to know the exact SAPI being used.
If all you need to know is whether you have an HTTP environment available, you can simply test for $_SERVER['HTTP_HOST']
:
$is_web = isset($_SERVER['HTTP_HOST']);
精彩评论