国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

cgi fast-cgi php-fpm三者的理解

libin19890520 / 465人閱讀

摘要:當(dāng)收到這個(gè)請求后,會啟動對應(yīng)的程序,這里就是的解析器。接下來解析器會解析文件,初始化執(zhí)行環(huán)境,然后處理請求,再以規(guī)定的規(guī)定的格式返回處理后的結(jié)果,退出進(jìn)程。當(dāng)請求過來時(shí),會傳遞給一個(gè),然后立即可以接受下一個(gè)請求。的管理對象是。

CGI

CGI, Common Gateway Interface, is a tool for HTTP server to contact with programs on other servers, which can be used into any languages with standard input, standard output and environmental variables, such as PHP, Perl, or Tcl.

FastCGI

FastCGI is a kind of CGI which is long-live, which will always be running. With FastCGI, it"ll take less time t fork(which is a problem of fork-and-execute mode in CGI). In additional, FastCGI also supports for distributed computing.
It is also not language related, which is an opened extension of CGI, which is used to keep CGI running in the memory. It"s well-known that loading of CGI has been the main reason of low performance.
the main process of running FastCGI:
Loading the Process Manager of FastCGI when a Web server has booted(IIS ISAPI or Apache Module)
The Process Manager of FastCGI will initiate itself to create several CGI processes, which are used to wait for connection of Web servers.
When requests from clients have reached the Web server, the Process Manager of FastCGI will select a CGI set up before to connect, whose environmental variables and standard input will be sent to the sub process php-cgi of FastCGI.
This sub process will return standard output and error info to the Web server with the same connection. Requests will be finished when it closes the connection.
Therefore, FastCGI only set once for parsing php.ini, loading extensions and initiating all the data structures.

shortcuts

Because of multi-processes, FastCGI will cost more memory than CGI, whose each process(PHP-CGI) will cost about 7Mb to 25Mb memory.
Data from the article: Nginx 0.8x + PHP 5.2.13(FastCGI) is 10 times better than Apache(Edition 6)
when 30k connection happens in parallel, 10 Nginx processes will only cost 150Mb Mem(15Mb 10), and 64 PHP-CGI will only cost about 1280Mb(20Mb 64).

PHP-CGI

PHP-CGI is one kind of the Process Manager of FastCGI, which is within php itself.
The command to boot is as follow:
php-cgi -b 127.0.0.1:9000
shortcuts

After changing php.ini, you should reboot PHP-CGI to make the new php.ini work.
When a PHP-CGI process is killed, all the PHP code will cannot run.(PHP-FPM and Spawn-FCGI do not have the same problem)

PHP-FPM

PHP-FPM is another kind of the Process Manager of FastCGI, which can be downloaded here.
It"s actually a patch for PHP, which is used to integrate the Process Manager of FastCGI into PHP, which should be make into PHP before version 5.3.2.
PHP-FPM can be used to control sub processes of PHP-CGI:
/usr/local/php/sbin/php-fpm [options]

# options --start: start a fastcgi process of php --stop: force to
kill a fastcgi process of php --quit: smooth to kill a fastcgi
process of php --restart: restart a fastcgi process of php --reload:
smooth to reload php.ini --logrotate: enable log files again

Spawn-FCGI Spawn-FCGI is a general kind of the Process Manager of
FastCGI, which is one part of lighttpd.

首先要明白CGI是干什么的?CGI是為了保證web server傳遞過來的數(shù)據(jù)是標(biāo)準(zhǔn)個(gè)數(shù)的,方便CGI程序的編寫者。

web server(比如說nginx)只是內(nèi)容的分發(fā)者。比如,如果請求/index.html,那么web
server會去文件系統(tǒng)中找到這個(gè)文件,發(fā)送給瀏覽器,這里分發(fā)的是靜態(tài)數(shù)據(jù)。好了,如果現(xiàn)在的請求是index.php,根據(jù)配置文件,nginx知道這個(gè)不是靜態(tài)文件,需要去找php解析器來處理,那么他會把這個(gè)請求簡單處理后交給php解析器。nginx會傳哪些數(shù)據(jù)給php解析器呢?url要有吧,查詢字符串也得有吧,POST數(shù)據(jù)也需要有,HTTP
header不能少吧,好的,CGI就是規(guī)定要傳哪些數(shù)據(jù),以什么樣的格式傳遞給后方處理這個(gè)請求的協(xié)議。仔細(xì)想想,你再PHP代碼中使用的用戶是從哪里來的。
當(dāng)web server收到/index.php
這個(gè)請求后,會啟動對應(yīng)的CGI程序,這里就是PHP的解析器。接下來PHP解析器會解析php.ini文件,初始化執(zhí)行環(huán)境,然后處理請求,再以規(guī)定的CGI規(guī)定的格式返回處理后的結(jié)果,退出進(jìn)程。web
server再把結(jié)果返回給瀏覽器。

明白了CGI是個(gè)協(xié)議,跟進(jìn)程什么的沒有關(guān)系。那fastcgi又是什么呢?Fasecgi是用來提高CGI程序性能的。

提高性能,那么CGI程序的性能問題在哪呢?“PHP解析器會解析php.ini文件,初始化執(zhí)行環(huán)境”,就是這里了。標(biāo)準(zhǔn)的CGI對每個(gè)請求文件都會執(zhí)行這些步驟(不嫌累啊!啟動進(jìn)程很累的說!),所以處理每個(gè)請求的時(shí)間會比較長。這明顯不合理嘛!那么Fastcgi是怎么做的呢?首先,F(xiàn)astcgi會先啟動一個(gè)master,解析配置環(huán)境,初始化執(zhí)行環(huán)境,然后再啟動多個(gè)worker。當(dāng)請求過來時(shí),master會傳遞給一個(gè)worker,然后立即可以接受下一個(gè)請求。這樣就避免了重復(fù)的勞動,效率自然是高。而且當(dāng)worker不夠用時(shí),master可以根據(jù)配置預(yù)先啟動幾個(gè)worker等著;當(dāng)然空閑worker太多時(shí),也會停掉一些,這樣就提高了性能,也節(jié)約了資源,這就是fastcgi對進(jìn)程的管理。

那PHP-FPM又是什么呢?是一個(gè)實(shí)現(xiàn)了Fastcgi的程序,被PHP官方收了。

大家都知道,PHP的解釋器是php-cgi。php-cgi只是個(gè)CGI程序,他自己本身只能解析請求,返回結(jié)果,不會進(jìn)程管理(皇上,臣妾真的做不到啊!)所以就出現(xiàn)了一些能夠調(diào)度php-cgi進(jìn)程的程序,比如說由lighthttpd分離出來的spawn-fcgi。好了PHP-FPM也是這么個(gè)東東,在長時(shí)間的發(fā)展后,逐漸得到了大家的認(rèn)可(要知道,前幾年大家可是抱怨php-fpm穩(wěn)定性太差的),也越來越流行。

好了,最后來回答你的問題。網(wǎng)上有的說,fastcgi是一個(gè)協(xié)議,php-fpm實(shí)現(xiàn)了這個(gè)協(xié)議。

有的說,php-fpm是fastcgi進(jìn)程的管理器,用來管理fastcgi進(jìn)程的

對。php-fpm的管理對象是php-cgi。但不能說php-fpm是fastcgi進(jìn)程的管理器,因?yàn)榍懊嬲f了fastcgi是個(gè)協(xié)議,似乎沒有這么個(gè)進(jìn)程存在,就算存在php-fpm也管理不了他(至少目前是)。

有的說,php-fpm是php內(nèi)核的一個(gè)補(bǔ)丁

以前是對的。因?yàn)樽铋_始的時(shí)候php-fpm沒有包含在php內(nèi)核里面,要使用這個(gè)功能,需要找到與源碼版本相同的php-fpm對內(nèi)核打補(bǔ)丁,然后再編譯。后來php內(nèi)核集成了php-fpm之后就方便多了,使用--enable-fpm這個(gè)編譯參數(shù)即可。

有的說,修改了php.ini配置文件后,沒辦法平滑重啟,所以就誕生了php-fpm

是的,修改php.ini之后,php-cgi進(jìn)程的確沒辦法平滑重啟的。php-fpm對此的處理機(jī)制是新的worker用新的配置,已經(jīng)存在的worker處理完手上的活就可以歇著了,通過這種機(jī)制來平滑過度。

還有的說php-cgi是php自帶的FastCGI管理器,那這樣的話干嗎又弄出個(gè)php-fpm出來
不對。php-cgi只是解釋php腳本的程序而已。

如何讓php更好的支持php-fpm

php-fpm提供了更好的php進(jìn)程管理方式,可以有效的控制內(nèi)存和進(jìn)程,可以平滑重載php配置。在./configure的時(shí)候帶-enable-fpm參數(shù)即可開啟php-fpm。
修改nginx配置文件已支持php-fpm

nginx安裝完場以后,修改nginx配置文件為nginx.conf
其中server段增加如下配置,否則會出現(xiàn)No input file specified.錯(cuò)誤 pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

啟動php-fpm和nginx

/usr/local/php/sbin/php-fpm

手動打補(bǔ)丁的啟動方式

/usr/local/php/sbin/php-fpm start

sudo /usr/local/nginx/nginx

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/25763.html

相關(guān)文章

  • cgi fast-cgi php-fpm三者理解

    摘要:當(dāng)收到這個(gè)請求后,會啟動對應(yīng)的程序,這里就是的解析器。接下來解析器會解析文件,初始化執(zhí)行環(huán)境,然后處理請求,再以規(guī)定的規(guī)定的格式返回處理后的結(jié)果,退出進(jìn)程。當(dāng)請求過來時(shí),會傳遞給一個(gè),然后立即可以接受下一個(gè)請求。的管理對象是。 CGI CGI, Common Gateway Interface, is a tool for HTTP server to contact with pro...

    eternalshallow 評論0 收藏0
  • cgi fast-cgi php-fpm三者理解

    摘要:當(dāng)收到這個(gè)請求后,會啟動對應(yīng)的程序,這里就是的解析器。接下來解析器會解析文件,初始化執(zhí)行環(huán)境,然后處理請求,再以規(guī)定的規(guī)定的格式返回處理后的結(jié)果,退出進(jìn)程。當(dāng)請求過來時(shí),會傳遞給一個(gè),然后立即可以接受下一個(gè)請求。的管理對象是。 CGI CGI, Common Gateway Interface, is a tool for HTTP server to contact with pro...

    appetizerio 評論0 收藏0
  • cgi和fast-cgi以及php-fpm聯(lián)系和區(qū)別

    摘要:解析器會解析文件,初始化執(zhí)行環(huán)境準(zhǔn)的對每個(gè)請求都會執(zhí)行這些步驟太累了對吧而且處理每個(gè)時(shí)間的時(shí)間會比較長首先,會先啟一個(gè),解析配置文件,初始化執(zhí)行環(huán)境,然后再啟動多個(gè)。當(dāng)請求過來時(shí),會傳遞給一個(gè),然后立即可以接受下一個(gè)請求。 簡單粗暴版本: cgi(公共網(wǎng)關(guān)接口) || 根據(jù)nginx配置文件,知道不是靜態(tài)文件 需要去找PHP解析器來處理 || ...

    coolpail 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<