How to Determine if PHP is Running via CGI/FastCGI or mod_php
Introduction
Whether PHP is running on a server via CGI/FastCGI or as an Apache module (mod_php) can be a crucial piece of information for development and troubleshooting purposes. This article explains how you can find out this information yourself, without contacting your hosting provider.
Server API Row in phpinfo() Output
One method is to examine the "Server API" row at the top of the phpinfo() output. This will typically have the following values:
php_sapi_name() Function
Another approach is to use the php_sapi_name() function or the PHP_SAPI constant. This function returns a lowercase string describing the type of server API being used. For example:
<code class="php">echo php_sapi_name();</code>
Note: It's important to check your hosting provider's documentation as they may offer multiple PHP versions available.
Running phpinfo() from the Correct Environment
It's crucial to run phpinfo() from the same environment you want to check. Running it from the command line will not provide information about the web server, and vice versa.
The above is the detailed content of How to Determine if PHP is Running via CGI/FastCGI or mod_php?. For more information, please follow other related articles on the PHP Chinese website!