>  기사  >  백엔드 개발  >  PHP에서 일반적으로 사용되는 4가지 실행 방법

PHP에서 일반적으로 사용되는 4가지 실행 방법

青灯夜游
青灯夜游앞으로
2020-04-21 09:34:563212검색

이 글에서는 일반적으로 사용되는 4가지 PHP 실행 방법인 CGI, FastCGI, APACHE2HANDLER 및 CLI를 소개합니다. 도움이 필요한 친구들이 모두 참고할 수 있기를 바랍니다.

PHP에서 일반적으로 사용되는 4가지 실행 방법

4 일반적으로 사용되는 PHP 실행 방법: CGI, FastCGI, APACHE2HANDLER, CLI.

1. CGI

CGI는 일반 게이트웨이 인터페이스(Common Gateway Interface)입니다. 일반 용어로 말하면, CGI는 웹 서버에서 웹 페이지와 실행 프로그램을 연결하는 다리와 같습니다. 수신된 명령어는 서버의 실행 프로그램으로 전달되고, 서버의 실행 프로그램의 결과는 HTML 페이지로 반환됩니다. CGI는 크로스 플랫폼이며 거의 모든 운영 체제에서 구현될 수 있습니다.

CGI 방법이 연결 요청(사용자 요청)을 발견하면 먼저 cgi 하위 프로세스를 생성하고 CGI 프로세스를 활성화한 다음 요청을 처리하고 처리 후 하위 프로세스를 종료해야 합니다. 이것이 포크 앤 실행 패턴입니다. 따라서 CGI를 사용하는 서버는 연결 요청만큼 많은 CGI 하위 프로세스를 가지게 됩니다. 하위 프로세스의 반복적인 로드는 CGI 성능이 저하되는 주요 원인입니다. 사용자 요청 수가 매우 많으면 메모리, CPU 시간 등 시스템 리소스를 많이 차지하게 되어 성능이 저하됩니다.

2. FastCGI

fast-cgi는 CGI의 업그레이드 버전입니다. FastCGI는 활성화된 한 항상 실행될 수 있습니다. 한 번 포크를 할 시간입니다. PHP는 관리를 위해 PHP FastCGI Process Manager의 전체 이름인 PHP-FPM(FastCGI Process Manager)을 사용합니다.

웹 서버가 시작될 때 FastCGI 프로세스 관리자(IIS ISAPI 또는 Apache 모듈)를 로드합니다. FastCGI 프로세스 관리자는 자체적으로 초기화되고 여러 CGI 인터프리터 프로세스(여러 php-cgi 표시)를 시작한 다음 웹 서버의 연결을 기다립니다.

클라이언트 요청이 웹 서버에 도달하면 FastCGI 프로세스 관리자가 CGI 인터프리터를 선택하고 연결합니다. 웹 서버는 CGI 환경 변수와 표준 입력을 FastCGI 하위 프로세스 php-cgi로 보냅니다.

FastCGI 하위 프로세스가 처리를 완료한 후 동일한 연결에서 표준 출력 및 오류 정보를 웹 서버로 반환합니다. FastCGI 하위 프로세스가 연결을 닫으면 요청이 처리됩니다. 그런 다음 FastCGI 하위 프로세스는 FastCGI 프로세스 관리자(웹 서버에서 실행)의 다음 연결을 기다리고 처리합니다. CGI 모드에서는 이 시점에서 php-cgi가 종료됩니다.

위의 경우 CGI가 일반적으로 얼마나 느린지 상상할 수 있습니다. PHP에 대한 모든 웹 요청은 php.ini를 다시 구문 분석하고, 모든 확장을 다시 로드하고, 모든 데이터 구조를 다시 초기화해야 합니다. FastCGI를 사용하면 이 모든 작업이 프로세스가 시작될 때 한 번만 발생합니다. 추가적인 이점은 지속적인 데이터베이스 연결이 작동한다는 것입니다.

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

함수 정보 보기

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 &#39;,&#39; or &#39;;&#39; 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 csdn.net에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제