首页 > 作文

php中常用的4种运行方式

更新时间:2023-04-08 12:34:10 阅读: 评论:0

本篇文章给大家介绍一下php的4种常用运行方式:cgi、fastcgi、apache2handler和cli。有一定的参考价值,有需要的朋友可以参考一狗的英语单词下,希望对大家有所帮助。

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 rver启动时载入fastcgi进程管理器(iis isapi或apache module)。fastcgi进程管理器自身初始化,启动多个cgi解释器进程(可见多个php-cgi)并等待来自web rver的连接。

当客户端请求到达web rver时,fastcgi进程管理器选择并连接到一个cgi解释器。web rver将cgi环境变量和标准输入发送到fastcgi子进程php-cgi。

fastcgi子进程完成处理后将标准输出和错误信息从同一连接返回web rver。当fastcgi子进程关闭连接时,请求便告处理完成。fastcgi子进程接着等待并处理来自fastcgi进程管理器(运行在web rver中)的下一个连接。 在cgi模式中,php-cgi在此便退出了。

在上述情况中,你可以想象cgi通常有多宠物狗图片大全慢。每一个web 请求php都必须重新解析php.ini、重新载入全部扩展并重初始化全部数据结构。使用fastcgi,所有这些都只在进程启动时发生一次。一个额外的 好处是,持续数据库连接(persistent databa connection)可以工作。

3、apache2handler

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

4、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 groupzend engine v2.5.0, copyright (c) 1998-2015 zend technologies 

  

查看当前php的扩展

eric:~ youngeric$ php -m  [php modules]bcmathbz2calendarcorectypecurldate......

  

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

eric:~ younge碳水化合物的食物有哪些ric$ 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/relea_x86_64 x86_64build date => oct 1 2016 23:01:51configure 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-sysvm' '--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-ur=_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'rver api => command line interfacevirtual directory support => disabledconfiguration file (php.ini) path => /usr/local/etc/php/5.5loaded configuration file => /usr/local/etc/php/5.5/php.iniscan 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 par error: syntax error, unexpected end of file, expecting ',' or ';' in jiance.php on line 3errors parsing jiance.php

  

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

eric:desktop youngeric$ php -s 127.0.0.1:8080  php 5.5.38 development rver started at thu dec 22 09:44:20 2016listening on http://127.0.0.1:8080document root is /urs/youngeric/desktoppress 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种运行方式的详细内容

更多学习内容请访问:

腾讯t3-t4标准精品php架构师教程目录大全,只要你看完保证薪资上升一个台阶(持续更新)

本文发布于:2023-04-08 12:34:08,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/0c18c1a03b6073d419088ff1cb2a1b35.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:php中常用的4种运行方式.doc

本文 PDF 下载地址:php中常用的4种运行方式.pdf

标签:进程   管理器   服务器   多个
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图