PHP的4种常用运行方式:CGI、FastCGI、APACHE2HANDLER、CLI。

1、CGI 
CGI即通用网关接口(common gatewag interface),它是一段程序,通俗的讲CGI就象是一座桥,把网页和WEB服务器中的执行程序连接起来,它把HTML接收的指令传递给服务器的执 行程序,再把服务器执行程序的结果返还给HTML页。CGI 的跨平台性能极佳,几乎可以在任何操作系统上实现。

CGI方式在遇到连接请求(用户 请求)先要创建cgi的子进程,激活一个CGI进程,然后处理请求,处理完后结束这个子进程。这就是fork-and-execute模式。所以用cgi 方式的服务器有多少连接请求就会有多少cgi子进程,子进程反复加载是cgi性能低下的主要原因。都会当用户请求数量非常多时,会大量挤占系统的资源如内 存,CPU时间等,造成效能低下。

2、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)可以工作。

3、APACHE2HANDLER 
PHP作为Apache模块,Apache服务器在系统启动后,预先生成多个进程副本驻留在内存中,一旦有请求出 现,就立即使用这些空余的子进程进行处理,这样就不存在生成子进程造成的延迟了。这些服务器副本在处理完一次HTTP请求之后并不立即退出,而是停留在计算机中等待下次请求。对于客户浏览器的请求反应更快,性能较高。

4、CLI 
cli是php的命令行运行模式,cli端的运行命令有时会很有用,以下总结几个:

查看php版本信息

eric:~ youngeric$ php -vPHP 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

查看当前php的扩展

eric:~ youngeric$ php -m[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

查看php.ini配置信息(相当于使用phpinfo()函数)

eric:~ youngeric$ php -iniphpinfo()
PHP Version => 5.5.38System => 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
......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

查看函数信息

eric:~ youngeric$ php --rf dateFunction [ <internal:date> function date ] {- Parameters [2] {Parameter #0 [ <required> $format ]Parameter #1 [ <optional> $timestamp ]}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

查看类信息

eric:~ youngeric$ php --rc  pdoClass [ <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 }......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

检测php代码

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

作为世界上最好的语言,php甚至还内置了服务器的功能(有没有很震惊的样子)。

eric:Desktop youngeric$ php -S 127.0.0.1:8080PHP 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的4种常用运行方式相关推荐

  1. html脚本语言居中,web前端:CSS--几种常用的水平垂直居中对齐方法

    层叠样式表(英文全称:CascadingStyleSheets)是一种用来表现html(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.css不仅可以静态地修 ...

  2. C#的6种常用集合类大比拼【月儿原创】

    C#的6种常用集合类大比拼 作者:清清月儿 主页:http://blog.csdn.net/21aspnet/           时间:2007.6.27 说明:MSDN没有说出几种集合类其间的区别 ...

  3. 基于 Python 的 8 种常用抽样方法

    抽样是统计学.机器学习中非常重要,也是经常用到的方法,因为大多时候使用全量数据是不现实的,或者根本无法取到.所以我们需要抽样,比如在推断性统计中,我们会经常通过采样的样本数据来推断估计总体的样本. 上 ...

  4. 详细介绍!Linux 上几种常用的文件传输方式

    点击上方"方志朋",选择"设为星标" 做积极的人,而不是积极废人 责编:乐乐 来源:https://dwz.cn/VWIHhsOw 昨天发布一篇Linux文章( ...

  5. CCTextFieldTTF 与 5种常用CCMenuItem

    //继承(class HelloWorld : public cocos2d::CCLayer, public cocos2d::CCTextFieldDelegate) CCTextFieldTTF ...

  6. 网页html文档头部声明的两种常用模式

    Html文档头部声明的两种常用模式 第一种,XHTML1.0严格模式,对很多废除的标签不支持,书写要严格遵守W3C的要求,是找虐的好方法: <!DOCTYPE html PUBLIC " ...

  7. Android中五种常用的menu

    Android Menu在手机的应用中起着导航的作用,作者总结了5种常用的Menu. 1.左右推出的Menu 前段时间比较流行,我最早是在海豚浏览器中看到的,当时耳目一新.最早使用左右推出菜单的,听说 ...

  8. 【方法整理】Oracle 获取trace跟踪文件名的几种常用方式

    [方法整理]Oracle 获取trace跟踪文件名的几种常用方式 1  BLOG文档结构图 2  前言部分 2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其 ...

  9. 负载均衡的几种常用方案

    负载均衡的几种常用方案 总结下负载均衡的常用方案及适用场景: Round Robin 轮询调度 以轮询的方式依次请求调度不同的服务器: 实现时,一般为服务器带上权重:这样有两个好处: 针对服务器的性能 ...

最新文章

  1. python模块和包用法详解(__all__)
  2. VMware宣布Big Data Extensions 2.0 GA
  3. Hadoop版本选择探讨
  4. CodeForces - 1255D Feeding Chicken(贪心+构造+模拟)
  5. 为什么不同的深度学习框架要使用不同的保存格式(转)
  6. charles 代理手机连不上网_Charles设置代理后,手机无法上网
  7. 计算机组成原理--数的表示及计算
  8. AMD and CMD are dead之KMD.js依赖可视化工具发布
  9. OAuth2.0 原理流程及其单点登录和权限控制
  10. Java多线程学习十六:读写锁 ReadWriteLock 获取锁有哪些规则
  11. 4-5 求自定类型元素的最大值 (10分)
  12. Oracle的数据并发与一致性详解(下)
  13. 保持进程在Shell退出后能继续运行的方法
  14. php千图网解析,PHP素材资源解析平台源码V8.0(thinkPHP框架内核)
  15. python爬取人口数据_爬取人口数据
  16. java调用webservice接口方法整理
  17. 一年工作经验的大专生程序员(java后台)
  18. TOEFL wordlist 16
  19. css 平行四边形 梯形 组合_CSS实现平行四边形布局
  20. matlab中marker太密,markersize_想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_

热门文章

  1. 《Python Enhancement Proposal #8》要点 学习摘录
  2. iOS开发 - 在状态栏显示FPS,CPU和内存信息
  3. windows知识点
  4. Head first 第一章
  5. 在线播放器 在网页中插入MediaPlayer 兼容IE和FF的代码调试
  6. TLStorm:APC UPS 存在零点击0day,可远程烧毁设备、切断电源
  7. 速更新!流行的开源邮件客户端 Mozilla Thunderbird 91.3修复多个高危缺陷
  8. 苹果修复严重的代码执行漏洞,影响 iOS 和 iPadOS 操作系统
  9. 大数据||MapReduce编程模板
  10. fiddler 抓取 安卓模拟器 https包