Home >Backend Development >PHP Tutorial >php如何在代码中判断运行方式是fastCgi还是CLI?

php如何在代码中判断运行方式是fastCgi还是CLI?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:14:181922browse

如题,例如在一个方法中,如何判断当前进程是由php-fpm启动的,还是直接在命令行启动的?

回复内容:

如题,例如在一个方法中,如何判断当前进程是由php-fpm启动的,还是直接在命令行启动的?

php_sapi_name http://php.net/manual/en/function.php-sapi-name.php

http://php.net/php_sapi_name
PHP的几种SAPI:
php(cli,cli-server)
php-fpm(fpm-fcgi)
php-cgi(cgi-fcgi)
libphp.so(apache2handler)

<code>PHP_SAPI || php_sapi_name</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn