Home  >  Article  >  Backend Development  >  How to Determine if PHP is Running via CGI/FastCGI or mod_php?

How to Determine if PHP is Running via CGI/FastCGI or mod_php?

Barbara Streisand
Barbara StreisandOriginal
2024-10-28 12:37:02682browse

How to Determine if PHP is Running via CGI/FastCGI or mod_php?

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:

  • Apache 2.0 Handler CGI/FastCGI: Indicates that PHP is running via CGI or FastCGI with Apache.
  • mod_php: Indicates that PHP is running as an Apache module.

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!

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