Sapi PHP theory basics

Hello everyone Studying Nginx, I got to the point that there are SAPI, and that there are several types of them, and blah, blah, blah. Question: we have a server (a daemon that waits for a request to come to it) and a processing mechanism (request/server - > pcp interpreter - > response/server)

The question arose in the light that the Apache in my eyes is:

  1. I received a request for port 80, and Apache is watching it.
  2. Seeing that there is a request, the daemon takes it into operation, and immediately uses its own module for processing

Whereas CGI/FastCGI/FPM ==> is the same, only the program that is on port 80 is different, and the php interpreter is installed as a standalone application, not a subroutine

Is it correct that SAPI is a mechanism that determines how and where the server will knock to process the request, as well as where and how to return this data back ?

Question 2: how does the system understand that I request came through the cli or mod_apache

Author: Alex Khonko, 2018-08-15

1 answers

Is it correct that SAPI is a mechanism that determines how and where the server will be knocking to process the request, as well as where and how to return this data back ?

Partially, if on the fingers then so:

[Клиент] <---> [WEB-Server] <----- SAPI ------> ([ZEND] <---> [PHP])

Whereas your CGI/FastCGI/FPM is just SAPI.

Visually, you can do this:

[Apache] <----- CGI------> [PHP]

Question 2: how does the system understand that I request came through the cli or mod_apache

Usually you only work with one SAPI.

You're a little confused. What does system mean? There is no system.

In general terms: Apache needs to process the request, it has a set of tools (SAPI) with which it can execute this request. Usually you take one tool that is beneficial for your task, and always work with it. You take for example CGI, and say ZEND-y, here I need the result of a specific script (apache already knows which one is needed), give me back the result, according to the standard CGI. Then ZEND says, do I have any information about what the standard CGI is, looks in his pocket and sees that there is (because everything that you have named is supported in php out of the box and even more). If there is, then we send it to the php interpreter, it gives the result and zend sends it back according to the standard.


In PHP, you can check SAPI like this: php_sapi_name().

 2
Author: Manitikyl, 2018-08-15 18:49:54