php 什么是 SAPI,什么时候使用它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9948008/
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-26 07:57:35  来源:igfitidea点击:

What is SAPI and when would you use it?

phpsapi

提问by jjmorph

I've been learning about error handling in PHP recently and came across the error_log()function.

我最近一直在学习 PHP 中的错误处理,并遇到了error_log()函数.

In the PHP manual, it talks about all the error log types and I understand all of them except for type 3 which states that the error message is sent directly to the SAPI logging handler. My question is what exactly is SAPI and when would you want to use it?

在 PHP 手册中,它讨论了所有错误日志类型,我理解所有错误日志类型,除了类型 3 指出错误消息直接发送到 SAPI 日志处理程序。我的问题是 SAPI 到底是什么,你想什么时候使用它?

采纳答案by Ignacio Vazquez-Abrams

SAPI stands for "Server API" (and API stands for "Application Programming Interface"). It is the mechanism that controls the interaction between the "outside world" and the PHP/Zend engine. So, you would always want to use it. In fact, you cannot avoid using it without a lot of effort since even CLI is considered a SAPI.

SAPI 代表“服务器 API”(API 代表“应用程序编程接口”)。它是控制“外部世界”与 PHP/Zend 引擎之间交互的机制。所以,你总是想使用它。事实上,你不能不付出很多努力就避免使用它,因为即使 CLI 也被认为是 SAPI。

回答by christian Nguyen

SAPI( Server Application Programming Interface ) also know as ISAPI( Internet Server Application Programming Interface) for Microsoft, NSAPI(Netscape Server Application Programming Interface) for Netscape.

SAPI(服务器应用程序编程接口)也称为Microsoft 的ISAPI(Internet 服务器应用程序编程接口),Netscape 的NSAPI(Netscape 服务器应用程序编程接口)。

APImeaning.

API 的意思。

For web developer, you can think of API such as REST, SOAP. You call a link you get a data from server. It allows you interact with the web server.

对于 Web 开发人员,您可以考虑 REST、SOAP 等 API。您调用一个从服务器获取数据的链接。它允许您与 Web 服务器交互。

SAPI is different with REST or SOAP, SAPI is API (contract) used for server.

SAPI 与 REST 或 SOAP 不同,SAPI 是用于服务器的 API(契约)。

For example: Common Gateway Interface is an SAPI. If a web server support CGI and another executable program implement it so web server can inteface and generate web pages dynamically.

例如:公共网关接口是一个 SAPI。如果一个 Web 服务器支持 CGI 并且另一个可执行程序实现它,那么 Web 服务器就可以动态地连接和生成网页。

Look the picture below:

看下图:

SAPI apache and php

SAPI apache 和 php

mod_php implement an interface which apache and php can understand each other.

mod_php 实现了一个 apache 和 php 可以相互理解的接口。

So what is SAPI exactly: It is a contract between Server (any kind of server) and the program. Just follow the contract and they don't need to know other side details.

那么究竟什么是 SAPI:它是服务器(任何类型的服务器)和程序之间的契约。只需遵守合同,他们就不需要知道其他方面的细节。

回答by numediaweb

From Wikipedia:

来自维基百科

In other words, SAPI is actually an application programming interface (API) provided by the web server to help other developers in extending the web server capabilities.

As an example, PHP has a direct module interface called SAPI for different web servers; in case of PHP 5 and Apache 2.0 on Windows, it is provided in form of a DLL file called php5apache2.dll, which is a module that, among other functions, provides an interface between PHP and the web server, implemented in a form that the server understands. This form is what is known as a SAPI.

There are different kinds of SAPIs for various web server extensions. For example, another two SAPIs for the PHP language are Common Gateway Interface (CGI) and command-line interface (CLI).

换句话说,SAPI 实际上是 Web 服务器提供的应用程序编程接口 (API),用于帮助其他开发人员扩展 Web 服务器功能。

例如,PHP 有一个名为 SAPI 的直接模块接口,用于不同的 Web 服务器;在 Windows 上的 PHP 5 和 Apache 2.0 的情况下,它以名为 php5apache2.dll 的 DLL 文件的形式提供,该模块除其他功能外,还提供 PHP 和 Web 服务器之间的接口,以一种形式实现服务器理解。这种形式就是所谓的 SAPI。

对于各种 Web 服务器扩展,有不同种类的 SAPI。例如,PHP 语言的另外两个 SAPI 是通用网关接口 (CGI) 和命令行接口 (CLI)。

回答by prosti

For PHP available SAPIs are: Apache2 (mod_php), FPM, CGI, FastCGI, and CLI.

对于 PHP,可用的 SAPI 有:Apache2 (mod_php)、FPM、CGI、FastCGI 和 CLI。

Arguable if API runs on the server it may be called SAPI.

有争议的是,如果 API 在服务器上运行,它可能被称为 SAPI。

Let me remind that FPM (FastCGI Process Manager) is very close to PHP FastCGI implementation with some additional features (mostly) useful for heavy-loaded sites.

让我提醒一下,FPM(FastCGI 进程管理器)非常接近 PHP FastCGI 实现,具有一些附加功能(大部分)对高负载站点有用。

Today, from the perspective of speed and efficiency FPM would be the most evolved SAPI. Apache or Nginx will perform better comparing the other mentioned SAPIs.

今天,从速度和效率的角度来看,FPM 将是最先进的 SAPI。与其他提到的 SAPI 相比,Apache 或 Nginx 的性能会更好。