php中常見的四種運(yùn)行方式

今天小編給大家分享的是php中常見的四種運(yùn)行方式,相信很多人都不太了解,為了讓大家更加了解php中常見的四種運(yùn)行方式,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會(huì)有所收獲的哦。

創(chuàng)新互聯(lián)專注于企業(yè)營(yíng)銷型網(wǎng)站、網(wǎng)站重做改版、甘井子網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、電子商務(wù)商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為甘井子等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

php中常見的四種運(yùn)行方式

PHP的4種常用運(yùn)行方式:CGI、FastCGI、APACHE2HANDLER、CLI。

1、CGI

CGI即通用網(wǎng)關(guān)接口(common gatewag interface),它是一段程序,通俗的講CGI就象是一座橋,把網(wǎng)頁(yè)和WEB服務(wù)器中的執(zhí)行程序連接起來(lái),它把HTML接收的指令傳遞給服務(wù)器的執(zhí) 行程序,再把服務(wù)器執(zhí)行程序的結(jié)果返還給HTML頁(yè)。CGI 的跨平臺(tái)性能極佳,幾乎可以在任何操作系統(tǒng)上實(shí)現(xiàn)。

CGI方式在遇到連接請(qǐng)求(用戶 請(qǐng)求)先要?jiǎng)?chuàng)建cgi的子進(jìn)程,激活一個(gè)CGI進(jìn)程,然后處理請(qǐng)求,處理完后結(jié)束這個(gè)子進(jìn)程。這就是fork-and-execute模式。所以用cgi 方式的服務(wù)器有多少連接請(qǐng)求就會(huì)有多少cgi子進(jìn)程,子進(jìn)程反復(fù)加載是cgi性能低下的主要原因。都會(huì)當(dāng)用戶請(qǐng)求數(shù)量非常多時(shí),會(huì)大量擠占系統(tǒng)的資源如內(nèi) 存,CPU時(shí)間等,造成效能低下。

2、FastCGI

fast-cgi 是cgi的升級(jí)版本,F(xiàn)astCGI像是一個(gè)常駐(long-live)型的CGI,它可以一直執(zhí)行著,只要激活后,不會(huì)每次都要花費(fèi)時(shí)間去fork一 次。PHP使用PHP-FPM(FastCGI Process Manager),全稱PHP FastCGI進(jìn)程管理器進(jìn)行管理。

Web Server啟動(dòng)時(shí)載入FastCGI進(jìn)程管理器(IIS ISAPI或Apache Module)。FastCGI進(jìn)程管理器自身初始化,啟動(dòng)多個(gè)CGI解釋器進(jìn)程(可見多個(gè)php-cgi)并等待來(lái)自Web Server的連接。

當(dāng)客戶端請(qǐng)求到達(dá)Web Server時(shí),F(xiàn)astCGI進(jìn)程管理器選擇并連接到一個(gè)CGI解釋器。Web server將CGI環(huán)境變量和標(biāo)準(zhǔn)輸入發(fā)送到FastCGI子進(jìn)程php-cgi。

FastCGI子進(jìn)程完成處理后將標(biāo)準(zhǔn)輸出和錯(cuò)誤信息從同一連接返回Web Server。當(dāng)FastCGI子進(jìn)程關(guān)閉連接時(shí),請(qǐng)求便告處理完成。FastCGI子進(jìn)程接著等待并處理來(lái)自FastCGI進(jìn)程管理器(運(yùn)行在Web Server中)的下一個(gè)連接。 在CGI模式中,php-cgi在此便退出了。

在上述情況中,你可以想象CGI通常有多慢。每一個(gè)Web 請(qǐng)求PHP都必須重新解析php.ini、重新載入全部擴(kuò)展并重初始化全部數(shù)據(jù)結(jié)構(gòu)。使用FastCGI,所有這些都只在進(jìn)程啟動(dòng)時(shí)發(fā)生一次。一個(gè)額外的 好處是,持續(xù)數(shù)據(jù)庫(kù)連接(Persistent database connection)可以工作。

3、APACHE2HANDLER

PHP作為Apache模塊,Apache服務(wù)器在系統(tǒng)啟動(dòng)后,預(yù)先生成多個(gè)進(jìn)程副本駐留在內(nèi)存中,一旦有請(qǐng)求出 現(xiàn),就立即使用這些空余的子進(jìn)程進(jìn)行處理,這樣就不存在生成子進(jìn)程造成的延遲了。這些服務(wù)器副本在處理完一次HTTP請(qǐng)求之后并不立即退出,而是停留在計(jì)算機(jī)中等待下次請(qǐng)求。對(duì)于客戶瀏覽器的請(qǐng)求反應(yīng)更快,性能較高。

4、CLI

cli是php的命令行運(yùn)行模式,cli端的運(yùn)行命令有時(shí)會(huì)很有用,以下總結(jié)幾個(gè):

查看php版本信息

eric:~ youngeric$ php -v
 
PHP 5.5.38 (cli) (built: Oct  1 2016 23:03:00) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

查看當(dāng)前php的擴(kuò)展

eric:~ youngeric$ php -m
 
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
......

查看php.ini配置信息(相當(dāng)于使用phpinfo()函數(shù))

eric:~ youngeric$ php -ini
 
phpinfo()
PHP Version => 5.5.38
 
System => Darwin eric.local 16.1.0 Darwin Kernel Version 16.1.0: Wed Oct 19 20:31:56 PDT 2016; root:xnu-3789.21.4~4/RELEASE_X86_64 x86_64
Build Date => Oct 1 2016 23:01:51
Configure Command => './configure' '--prefix=/usr/local/Cellar/php55/5.5.38_11' '--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/5.5' '--with-config-file-path=/usr/local/etc/php/5.5' '--with-config-file-scan-dir=/usr/local/etc/php/5.5/conf.d' '--mandir=/usr/local/Cellar/php55/5.5.38_11/share/man' '--enable-bcmath' '--enable-calendar' '--enable-dba' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-mbregex' '--enable-mbstring' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--enable-zip' '--with-freetype-dir=/usr/local/opt/freetype' '--with-gd' '--with-gettext=/usr/local/opt/gettext' '--with-iconv-dir=/usr' '--with-icu-dir=/usr/local/opt/icu4c' '--with-jpeg-dir=/usr/local/opt/jpeg' '--with-kerberos=/usr' '--with-libedit' '--with-mhash' '--with-ndbm=/usr' '--with-png-dir=/usr/local/opt/libpng' '--with-xmlrpc' '--with-zlib=/usr' '--with-readline=/usr/local/opt/readline' '--without-gmp' '--without-snmp' '--with-libxml-dir=/usr/local/opt/libxml2' '--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc' '--with-unixODBC=/usr/local/opt/unixodbc' '--with-bz2=/usr' '--with-openssl=/usr/local/opt/openssl' '--enable-fpm' '--with-fpm-user=_www' '--with-fpm-group=_www' '--with-curl' '--with-xsl=/usr' '--with-ldap' '--with-ldap-sasl=/usr' '--with-MySQL-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--disable-opcache' '--enable-pcntl' '--without-pear' '--enable-dtrace' '--disable-phpdbg' '--enable-zend-signals'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc/php/5.5
Loaded Configuration File => /usr/local/etc/php/5.5/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/5.5/conf.d
......

查看函數(shù)信息

eric:~ youngeric$ php --rf date
 
Function [ <internal:date> function date ] {
 - Parameters [2] {
  Parameter #0 [ <required> $format ]
  Parameter #1 [ <optional> $timestamp ]
 }
}

查看類信息

eric:~ youngeric$ php --rc pdo
 
Class [ <internal:PDO> class PDO ] {
 
 - Constants [89] {
  Constant [ integer PARAM_BOOL ] { 5 }
  Constant [ integer PARAM_NULL ] { 0 }
  Constant [ integer PARAM_INT ] { 1 }
  Constant [ integer PARAM_STR ] { 2 }
  Constant [ integer PARAM_LOB ] { 3 }
  Constant [ integer PARAM_STMT ] { 4 }
  Constant [ integer PARAM_INPUT_OUTPUT ] { 2147483648 }
 ......

檢測(cè)php代碼

eric:~ youngeric$ php -l jiance.php
 
PHP Parse error: syntax error, unexpected end of file, expecting ',' or ';' in jiance.php on line 3
Errors parsing jiance.php

作為世界上最好的語(yǔ)言,php甚至還內(nèi)置了服務(wù)器的功能(有沒(méi)有很震驚的樣子)。

eric:Desktop youngeric$ php -S 127.0.0.1:8080
 
PHP 5.5.38 Development Server started at Thu Dec 22 09:44:20 2016
Listening on http://127.0.0.1:8080
Document root is /Users/youngeric/Desktop
Press Ctrl-C to quit.
[Thu Dec 22 09:44:29 2016] 127.0.0.1:52988 [404]: / - No such file or directory
[Thu Dec 22 09:44:29 2016] 127.0.0.1:52989 [404]: /favicon.ico - No such file or directory

以上就是php中常見的四種運(yùn)行方式的詳細(xì)內(nèi)容了,看完之后是否有所收獲呢?如果想了解更多相關(guān)內(nèi)容,歡迎來(lái)創(chuàng)新互聯(lián)行業(yè)資訊!

網(wǎng)頁(yè)標(biāo)題:php中常見的四種運(yùn)行方式
網(wǎng)頁(yè)地址:http://bm7419.com/article26/pcgcjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)用戶體驗(yàn)、Google虛擬主機(jī)、網(wǎng)站內(nèi)鏈、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)