php_sapi_name()

php_sapi_name() — Returns the type of interface between web server and PHP.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Returns a lowercase string that describes the type of interface (the Server API, SAPI) that PHP is using. For example, in CLI PHP this string will be "cli" whereas with Apache it may have several different values depending on the exact SAPI used. Possible values are listed below.

Signature

php_sapi_name(): string|false

Parameters

This function takes no parameters.

Return value

Returns the interface type, as a lowercase string, or false on failure. Although not exhaustive, the possible return values include apache, apache2handler, cgi (until PHP 5.3), cgi-fcgi, cli, cli-server, embed, fpm-fcgi, litespeed, phpdbg.

Example

A runnable snippet:

$sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) == 'cgi') { echo "You are using CGI PHP\n"; } else { echo "You are not using CGI PHP\n"; }

All PHP 8.5 built-in functions

Reference card built from the PHP manual page php_sapi_name() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.