了解 PHP 如何在服务器上运行(CGI 或 fastCGI 或 mod_php)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16414054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:04:53  来源:igfitidea点击:

Find out how PHP is running on server (CGI OR fastCGI OR mod_php)

phpapache

提问by Oto Shavadze

I use shared hosting.

我使用共享主机。

There is possible to find out whether PHP is running via fastCGI (or maybe CGI) or as Apache module mod_php?

有可能找出 PHP 是通过 fastCGI(或者可能是 CGI)还是作为 Apache 模块运行mod_php

Is it possibly to find out by myself, without asking the hoster?

不问房东就可以自己查吗?

回答by álvaro González

That's the Server APIrow on top of phpinfo()'soutput:

这是phpinfo()输出顶部的服务器 API行:

Server API

服务器接口

However, please note that it won't tell you the exact version of Apache or the exact CGI handler. It just describes the SAPI in use.

但是,请注意,它不会告诉您 Apache 的确切版本或确切的 CGI 处理程序。它只是描述了正在使用的 SAPI。

You can also call the php_sapi_name()function (or the PHP_SAPIconstant, which provides the same info):

您还可以调用php_sapi_name()函数(或提供相同信息的PHP_SAPI常量):

Description

string php_sapi_name ( void )

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

描述

string php_sapi_name ( void )

返回描述 PHP 使用的接口类型(服务器 API,SAPI)的小写字符串。例如,在 CLI PHP 中,这个字符串将是“cli”,而在 Apache 中,它可能有几个不同的值,具体取决于所使用的确切 SAPI

It's still a good idea to check your HSP's documentation because it possible to have several PHP versions available.

检查您的 HSP 文档仍然是一个好主意,因为可能有多个 PHP 版本可用。



Remember you need to run phpinfo()from the same environment you want to check (web server won't tell you about command line and vice-versa):

请记住,您需要phpinfo()从要检查的相同环境中运行(Web 服务器不会告诉您有关命令行的信息,反之亦然):

C:\>php -i | findstr /C:"Server API"
Server API => Command Line Interface
$ php -i | grep 'Server API'
Server API => Command Line Interface

回答by Prashant Barve

You can use the link below: How to determine php is running as php cgi or apache module?

您可以使用以下链接: 如何确定 php 作为 php cgi 或 apache 模块运行?

or create a file info.phpand type

或创建一个文件info.php并键入

<?php 
    phpinfo(); 
?>

now run file with your domain name.

现在使用您的域名运行文件。

find Server API on file and it show you PHP is running on server with CGI OR Apache

在文件中找到服务器 API,它会显示 PHP 正在使用 CGI 或 Apache 的服务器上运行

Security consideration: Make sure to delete the file which outputs phpinfo()especially if the website is or is going to be hosted online. The information shown there is a gold mine for hackers.

安全考虑:确保删除输出的文件,phpinfo()尤其是当网站正在或将要在线托管时。显示的信息是黑客的金矿。