在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ngx_php7开源软件地址:https://gitee.com/mirrors/ngx_php7开源软件介绍:ngx_php7ngx_php7 is an extension module of high-performance web server nginx, which implements embedded php7 script to process nginx location and variables. ngx_php7 draws on the design of ngx_lua and is committed to providing non-blocking web services with significant performance advantages over php-cgi, mod_php, php-fpm and hhvm. ngx_php7 doesn't want to replace anything, just want to provide a solution. There is a legacy version of ngx_php5, which records some of my past code practices and is also valuable. Benchmarks about ngx_php7 and php Table of contents
What's different with official php
Requirement
InstallationCompile install$ wget 'http://php.net/distributions/php-7.3.10.tar.gz'$ tar xf php-7.3.10.tar.gz$ cd php-7.3.10$ ./configure --prefix=/path/to/php --enable-embed$ make && make install$ git clone https://github.com/rryqszq4/ngx_php7.git$ wget 'http://nginx.org/download/nginx-1.12.2.tar.gz'$ tar -zxvf nginx-1.12.2.tar.gz$ cd nginx-1.12.2$ export PHP_CONFIG=/path/to/php/bin/php-config$ export PHP_BIN=/path/to/php/bin$ export PHP_INC=/path/to/php/include/php$ export PHP_LIB=/path/to/php/lib$ ./configure --user=www --group=www \$ --prefix=/path/to/nginx \$ --with-ld-opt="-Wl,-rpath,$PHP_LIB" \$ --add-module=/path/to/ngx_php7/third_party/ngx_devel_kit \$ --add-module=/path/to/ngx_php7$ make && make install CentOS / RedHat 7yum -y install https://extras.getpagespeed.com/release-el7-latest.rpmyum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-utilsyum-config-manager --enable remi-php73yum install nginx-module-php7 Edit load_module modules/ndk_http_module.so;load_module modules/ngx_http_php_module.so; Ubuntuapt-get update -yqq && apt-get install -yqq software-properties-commonLC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/phpapt-get update -yqqapt-get install -yqq wget git unzip libxml2-dev cmake make systemtap-sdt-dev \ zlib1g-dev libpcre3-dev libargon2-0-dev libsodium-dev \ php7.4-cli php7.4-dev libphp7.4-embed php7.4-mysqlgit clone https://github.com/rryqszq4/ngx_php7.gitwget 'http://nginx.org/download/nginx-1.18.0.tar.gz'tar -zxvf nginx-1.18.0.tar.gzcd nginx-1.18.0export PHP_LIB=/usr/lib./configure --user=www --group=www \ --prefix=/path/to/nginx \ --with-ld-opt="-Wl,-rpath,$PHP_LIB" \ --add-module=/path/to/ngx_php7/third_party/ngx_devel_kit \ --add-module=/path/to/ngx_php7make && make install Mac osxhttps://github.com/rryqszq4/ngx_php7/blob/master/docs/zh-cn/osx_install.md Docker$ docker build -t nginx-php7 .$ : "app.conf: Create nginx config"$ docker run -p 80:80 -v $PWD/app.conf:/etc/nginx/conf.d/default.conf nginx-php7 Synopsisworker_processes auto;events { worker_connections 102400;}http { include mime.types; default_type application/octet-stream; keepalive_timeout 65; client_max_body_size 64k; client_body_buffer_size 64k; php_ini_path /usr/local/php/etc/php.ini; server { listen 80; server_name localhost; default_type 'application/json; charset=UTF-8'; location /php { content_by_php_block { echo "hello ngx_php7"; } } location = /ngx_request { content_by_php_block { echo ngx_request_document_uri(); } } # curl /ngx_get?a=1&b=2 location = /ngx_get { content_by_php_block { echo "ngx_query_args()\n"; var_dump(ngx_query_args()); } } # curl -d 'a=1&b=2' /ngx_post location = /ngx_post { content_by_php_block { echo "ngx_post_args()\n"; var_dump(ngx_post_args()); } } location = /ngx_sleep { content_by_php_block { echo "ngx_sleep start\n"; yield ngx_sleep(1); echo "ngx_sleep end\n"; } } location = /ngx_socket2 { default_type 'application/json;charset=UTF-8'; content_by_php_block { $fd = ngx_socket_create(); yield ngx_socket_connect($fd, "hq.sinajs.cn", 80); $send_buf = "GET /list=s_sh000001 HTTP/1.0\r\n Host: hq.sinajs.cn\r\nConnection: close\r\n\r\n"; yield ngx_socket_send($fd, $send_buf, strlen($send_buf)); $recv_buf = ""; yield ngx_socket_recv($fd, $recv_buf); var_dump($recv_buf); yield ngx_socket_close($fd); } } location = /ngx_var { set $a 1234567890; content_by_php_block { $a = ngx_var_get("a"); var_dump($a); } } # set content-type of response headers location = /ngx_header { content_by_php_block { ngx_header_set("Content-Type", "text/html; charset=UTF-8"); } } # run a php file location = /php { content_by_php_block { include "name_of_php_file.php"; } } # run any php file in root location = / { content_by_php_block { include ngx_var_get("uri"); } } }} TestUsing the perl of Test::Nginx module to testing, searching and finding out problem in ngx_php7. ngx_php7 test ...nginx version: nginx/1.12.2built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configure arguments: --prefix=/home/travis/build/rryqszq4/ngx_php7/build/nginx --with-ld-opt=-Wl,-rpath,/home/travis/build/rryqszq4/ngx_php7/build/php/lib --add-module=../../../ngx_php7/third_party/ngx_devel_kit --add-module=../../../ngx_php7t/001-hello.t ..................... okt/002-ini.t ....................... okt/003-error.t ..................... okt/004-ngx_request.t ............... okt/005-ngx_log.t ................... okt/006-ngx_sleep.t ................. okt/007-ngx_socket.t ................ okt/008-ngx_exit.t .................. okt/009-ngx_query_args.t ............ okt/010-ngx_post_args.t ............. okt/011-ngx_constants.t ............. okt/012-function.t .................. okt/013-class.t ..................... okt/014-ngx_var.t ................... okt/015-ngx_header.t ................ 1/? WARNING: TEST 2: set content-length of response headers - unexpected extra bytes after last chunk in response: "Testing ngx_header!\x{0a}"t/015-ngx_header.t ................ okt/016-rewrite_by_php.t ............ okt/017-ngx_redirect.t .............. okt/018-ngx_mysql.t ................. okt/019-php_set.t ................... okt/020-ngx_cookie.t ................ okt/021-content_by_php_block.t ...... okt/022-init_worker_by_php_block.t .. okAll tests successful.Files=22, Tests=84, 14 wallclock secs ( 0.09 usr 0.02 sys + 2.19 cusr 0.43 csys = 2.73 CPU)Result: PASS Directives
php_ini_pathsyntax: context: phase: This directive allows loading the official php configuration file php.ini, which will be used by subsequent PHP code. init_worker_by_phpsyntax: context: phase: init_worker_by_php_blocksyntax: context: phase: rewrite_by_phpsyntax: context: phase: In the rewrite phase of nginx, you can execute inline php code. rewrite_by_php_blocksyntax: context: phase: In the rewrite phase of nginx, you can execute inline php code. access_by_phpsyntax: context: phase: In the access phase of nginx, you can execute inline php code. access_by_php_blocksyntax: context: phase: In the access phase of nginx, you can execute inline php code. content_by_phpsyntax: context: phase: In the content phase of nginx, you can execute inline php code. content_by_php_blocksyntax: context: phase: In the content phase of nginx, you can execute inline php code. log_by_phpsyntax: context: phase: log_by_php_blocksyntax: context: phase: header_filter_by_phpsyntax: context: phase: header_filter_by_php_blocksyntax: context: phase: body_filter_by_phpsyntax: context: phase: body_filter_by_php_blocksyntax: context: phase: php_keepalivesyntax: default: context: In php, set upstream connection pool size. php_setsyntax: context: phase: Installs a php handler for the specified variable. php_socket_keepalivesyntax: default: context: php_socket_buffer_sizesyntax: default: context: Nginx API for php
ngx_exitsyntax: parameters:
context: End of current request and return http status code. ngx_query_argssyntax: parameters:
context: An associative array of variables passed to the current script via the URL parameters (aka. query string). ngx_post_argssyntax: parameters:
context: An associative array of variables passed to the current script via the HTTP POST method ngx_log_errorsyntax: parameters:
context: ngx_request_methodsyntax: parameters:
context: Which request method was used to access the page, such as 'GET','POST','PUT','DELETE' and so on. ngx_request_document_rootsyntax: parameters:
context: The document root directory under which the current script is executing, as defined in the server's configuration file. ngx_request_document_urisyntax: parameters:
context: ngx_request_script_namesyntax: parameters:
context: Contains the current script'path. This is useful for pages which need to point to the themselves. ngx_request_script_filenamesyntax: parameters:
context: The absolute pathname of the currently executing script file name. ngx_request_query_stringsyntax: parameters:
context: The query string, if any, via which the page was accessed. ngx_request_urisyntax: parameters:
context: The URI which was given in order to access this page, for instance, '/index.html'. ngx_request_server_protocolsyntax: parameters:
context: Name and revision of th information protocol via which the page was requested, such as 'HTTP/1.0'. ngx_request_remote_addrsyntax: parameters:
context: The IP address from which the user is viewing the current page. ngx_request_server_addrsyntax: parameters:
context: The IP address of the server under which the current script is executing. ngx_request_remote_portsyntax: parameters:
context: The port being used on the user's machine to communicate with the web server. ngx_request_server_portsyntax: parameters:
context: The port on the server machine being used by the web server for communication. For default setups, ngx_request_server_namesyntax: parameters:
context: The name of the server host under which the current script is executing. ngx_request_headerssyntax: parameters:
context: Get the header full information of the http request. ngx_var_getsyntax: parameters:
context: Get the variables in the nginx configuration. ngx_var_setsyntax: parameters:
context: Set the variables in the nginx configuration. ngx_header_setsyntax: parameters:
context: Set the header information of the http response. ngx_header_getsyntax: parameters:
context: Get the header information of the http response. ngx_header_getssyntax: parameters:
context: Get the header full information of the http response. ngx_redirectsyntax: parameters:
context: Set response header redirection. ngx_cookie_get_allsyntax: parameters:
context: ngx_cookie_getsyntax: parameters:
context: ngx_cookie_setsyntax: parameters:
context: Nginx non-blocking API for php
ngx_sleepsyntax: parameters:
context: Delays the program execution for the given number of seconds. ngx_msleepsyntax: parameters:
context: Delays the program execution for the given number of milliseconds. ngx_socket_createsyntax: parameters:
context: Creates and returns a socket resource, also referred to as an endpoint of communication. ngx_socket_iskeepalivesyntax: parameters:
context: ngx_socket_connectsyntax: parameters:
context: Initiate a connection to address using the socket resource socket, which must be a valid ngx_socket_closesyntax: parameters:
context: ngx_socket_close() closes the socket resource given by socket. This function is specific to ngx_socket_sendsyntax: parameters:
context: The function ngx_socket_send() sends len bytes to the socket socket from buf. ngx_socket_recvsyntax: parameters:
context: The ngx_socket_recv() function receives len bytes of data in buf from socket. ngx_socket_recv() can be buf is passed by reference, so it must be specified as a variable in the argument list. ngx_socket_recvpagesyntax: parameters:
context: ngx_socket_recvsyncsyntax: parameters:
context: ngx_socket_clearsyntax: parameters:
context: Close the socket resource and is blocking but hight performance. Nginx constantsversion constants
log constants for php
status constants for php
http status constants for php
Copyright and LicenseCopyright (c) 2016-2020, rryqszq4 <[email protected]>All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
请发表评论