php中常用的4种运行方式-php教程

资源魔 23 0
本篇文章给各人引见一下php的4种罕用运转形式:CGI、FastCGI、APACHE2HANDLER以及CLI。有肯定的参考代价,有需求的冤家能够参考一下,心愿对各人有所协助。

PHP的4种罕用运转形式:CGI、FastCGI、APACHE2HANDLER、CLI。

一、CGI

CGI即通用网关接口(co妹妹on gatewag interface),它是一段顺序,浅显的讲CGI就象是一座桥,把网页以及WEB效劳器中的执行顺序衔接起来,它把HTML接纳的指令通报给效劳器的执 行顺序,再把效劳器执行顺序的后果返还给HTML页。CGI 的跨平台功能极佳,简直能够正在任何操作零碎上完成。

CGI形式正在遇到衔接申请(用户 申请)先要创立cgi的子过程,激活一个CGI过程,而后解决申请,解决完后完结这个子过程。这就是fork-and-execute模式。以是用cgi 形式的效劳器有几何衔接申请就会有几何cgi子过程,子过程重复加载是cgi功能低下的次要缘由。城市当用户申请数目十分多时,会年夜量挤占零碎的资本如内 存,CPU工夫等,造成效力低下。

二、FastCGI

fast-cgi 是cgi的晋级版本,FastCGI像是一个常驻(long-live)型的CGI,它能够不断执行着,只需激活后,没有会每一次都要破费工夫去fork一 次。PHP应用PHP-FPM(FastCGI Process Manager),全称PHP FastCGI过程治理器进行治理。

Web Server启动时载入FastCGI过程治理器(IIS ISAPI或Apache Module)。FastCGI过程治理器本身初始化,启动多个CGI诠释器过程(可见多个php-cgi)并期待来自Web Server的衔接。

当客户端申请抵达Web Server时,FastCGI过程治理器抉择并衔接到一个CGI诠释器。Web server将CGI环境变量以及规范输出发送到FastCGI子过程php-cgi。

FastCGI子过程实现解决后将规范输入以及谬误信息从同一衔接前往Web Server。当FastCGI子过程封闭衔接时,申请便告解决实现。FastCGI子过程接着期待并解决来自FastCGI过程治理器(运转正在Web Server中)的下一个衔接。 正在CGI模式中,php-cgi正在此便加入了。

正在上述状况中,你能够设想CGI通常有多慢。每个Web 申请PHP都必需从新解析php.ini、从新载入全副扩大并重初始化全副数据构造。应用FastCGI,一切这些都只正在过程启动时发作一次。一个额定的 益处是,继续数据库衔接(Persistent database connection)能够工作。

三、APACHE2HANDLER

PHP作为Apache模块,Apache效劳器正在零碎启动后,事后天生多个过程正本驻留正在内存中,一旦有申请出 现,就立刻应用这些空余的子过程进行解决,这样就没有存正在天生子过程酿成的提早了。这些效劳器正本正在解决完一次HTTP申请之后其实不立刻加入,而是停留正在较量争论机中期待下次申请。关于客户阅读器的申请反响更快,功能较高。

四、CLI

cli是php的饬令交运行模式,cli真个运转饬令有时会颇有用,如下总结几个:

查看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

查看以后php的扩大

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

查看php.ini设置装备摆设信息(相称于应用phpinfo()函数)

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 Co妹妹and => './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 => Co妹妹and 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
......

查看函数信息

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 }
 ......

检测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

作为世界上最佳的言语,php乃至还内置了效劳器的性能(有无很震惊的样子)。

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视频教程

以上就是php中罕用的4种运转形式的具体内容,更多请存眷资源魔其它相干文章!

标签: php php开发教程 php开发资料 php开发自学

抱歉,评论功能暂时关闭!