In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how workerman programs run in PHP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
We know that workerman programs need to be run in php-cli mode, that is, command line mode, which we need to know. It is said that there are four operation modes of PHP, namely, CGI, FastCGI, CLI and Web module mode.
CGI
The full name is "Universal Gateway Interface" (CommonGatewayInterface), which allows a client to request data from a web browser to a program executed on a Web server, describing a standard for transferring data between the client and the program. In addition, CGI is independent of any language, so it can be written in any language, as long as the language has standard input, output and environment variables. Such as php,perl,tcl, etc.
CGI runs separate child processes for each user request to maintain, so performance problems occur when there are a large number of them, which have been rarely used in recent years.
FastCGI
In the upgraded version of CGI, FastCGI is like a resident (long-live) CGI, which can be executed all the time, as long as it does not take time to parse php.ini, reload all dll extensions, and reinitialize all data structures every time after activation.
PHP is managed using PHP-FPM (FastCGIProcessManager), the full name PHPFastCGI process Manager.
How FastCGI works
Load the FastCGI process Manager when WebServer starts
The FastCGI process manager initializes itself, starts multiple CGI interpreter processes and waits for a connection from WebServer
When the client request arrives at WebServer, the FastCGI process manager selects and connects to a CGI interpreter. Webserver sends CGI environment variables and standard input to the FastCGI child process php-cgi.
The FastCGI child process returns standard output and error messages from the same connection to WebServer after processing. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits and processes the next connection from the FastCGI process manager.
In normal CGI mode, this is over, and you have to start over next time. But in FastCGI, all of this happens only once when the process starts. An added benefit is that persistent database connections (Persistentdatabaseconnection) work.
Cli
PHP-CLI is the abbreviation of PHPCommandLineInterface, which is the interface that PHP runs on the command line, which is different from the PHP environment (PHP-CGI, etc.) running on the Web server.
We often use "php-m" under Linux to find which extensions are installed by PHP, which is the PHP command-line run mode. You can tap into php-h to see what the specific commands are.
In php-cli mode, we can directly start a php file and execute it, just like in workerman
Phpindex.phpstart
To be clear, the php-cli mode does not say that php runs out of time.
Module loading
Generally speaking, it is for apache. In this way, their common essence is to use LoadModule to load phpX_module, that is, to run php as a submodule of apache. When the php file is accessed through web, apache calls phpX_module to parse the php code, so how does phpX_module pass the data to the php parser to parse the php code? The answer is through sapi.
Therefore, the above apache calls php to perform the following process:
Apache- > httpd- > php5_module- > sapi- > php
Every time apache receives a request, it will generate a process to connect to php to complete the request through sapi. It is conceivable that if there are too many users and too many concurrency, the server will not be able to bear it.
Moreover, when compiling mod_php into apache, it is difficult to locate whether it is the problem of php or apache when something goes wrong.
Summary
If you want to build a high-performance PHPWEB server, the best way at present is Apache/Nginx+FastCGI+PHP-FPM (+ PHP-CGI), instead of using Module loading or CGI.
Thank you for reading! This is the end of this article on "what are the running modes of workerman programs in PHP?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.