开发者

Methods to determine if PHP is running from a shell or within apache? [duplicate]

开发者 https://www.devze.com 2023-04-01 15:54 出处:网络
This question already has answers here:开发者_C百科 Closed 11 years ago. Possible Duplicate: How to differentiate between http and cli requests?
This question already has answers here: 开发者_C百科 Closed 11 years ago.

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']);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号