Skip to content

Commit 46f9ae3

Browse files
committed
1 parent 41d60b2 commit 46f9ae3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1144
-107
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ compiler:
2727
cache:
2828
- apt
2929
env:
30-
- PHP_SRC_VERSION=7.0.29
30+
- PHP_SRC_VERSION=7.0.30
3131
NGINX_SRC_VERSION=1.10.3
32-
- PHP_SRC_VERSION=7.1.16
32+
- PHP_SRC_VERSION=7.1.19
3333
NGINX_SRC_VERSION=1.10.3
34-
- PHP_SRC_VERSION=7.2.4
34+
- PHP_SRC_VERSION=7.2.7
3535
NGINX_SRC_VERSION=1.10.3
36+
- PHP_SRC_VERSION=7.2.7
37+
NGINX_SRC_VERSION=1.10.3
38+
NGINX_MODULE=DYNAMIC
3639
install:
3740
- sudo cpanm -n Test::Nginx
3841
before_script:

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
ngx_php7 0.0.13 changes: 15 Sep 2018
2+
* Add directive header_filter_by_php, body_filter_by_php, init_worker_by_php, log_by_php.
3+
4+
* Add php impl ngx_var::get, ngx_var::set.
5+
6+
* Supports dynamic module by kjdev.
7+
8+
* Hello world test performance.
9+
110
ngx_php7 0.0.12 changes: 10 Apr 2018
211
* Add php impl ngx_socket::connect, ngx_socket::send, ngx_socket::recv, ngx_socket::close.
312

README.md

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<div align="left">
2-
<a href="https://github.com/rryqszq4/ngx_php7"><img width="320" src="https://raw.githubusercontent.com/rryqszq4/ngx_php7/master/docs/ngx_php7_logo_v0.2.png"></a>
3-
</div>
4-
1+
ngx_php7
2+
========
53
[![Build Status](https://travis-ci.org/rryqszq4/ngx_php7.svg?branch=master)](https://travis-ci.org/rryqszq4/ngx_php7)
4+
[![GitHub release](https://img.shields.io/github/release/rryqszq4/ngx_php7.svg)](https://github.com/rryqszq4/ngx_php7/releases/latest)
65
[![license](https://img.shields.io/badge/license-BSD--2--Clause-blue.svg)](https://github.com/rryqszq4/ngx_php7/blob/master/LICENSE)
76
[![QQ group](https://img.shields.io/badge/QQ--group-558795330-26bcf5.svg)](https://github.com/rryqszq4/ngx_php7)
87

8+
![](https://raw.githubusercontent.com/rryqszq4/ngx_php7/master/docs/hello_world_performance.png)
9+
910
[ngx_php7](https://github.com/rryqszq4/ngx_php7) - Embedded php7 programming language for nginx-module.
1011
[ngx_php](https://github.com/rryqszq4/ngx_php) - Embedded php5 script language for nginx-module.
1112

@@ -80,13 +81,15 @@ http {
8081
';
8182
}
8283
84+
# curl /ngx_get?a=1&b=2
8385
location = /ngx_get {
8486
content_by_php '
8587
echo "ngx::query_args()\n";
8688
var_dump(ngx::query_args());
8789
';
8890
}
8991
92+
# curl -d 'a=1&b=2' /ngx_post
9093
location = /ngx_post {
9194
content_by_php '
9295
echo "ngx::post_args()\n";
@@ -106,18 +109,113 @@ http {
106109
default_type 'application/json;charset=UTF-8';
107110
content_by_php '
108111
yield ngx_socket::connect("hq.sinajs.cn", 80);
109-
yield ngx_socket::send("GET /list=s_sh000001 HTTP/1.0\r\nHost: hq.sinajs.cn\r\nConnection: close\r\n\r\n");
112+
yield ngx_socket::send("GET /list=s_sh000001 HTTP/1.0\r\n
113+
Host: hq.sinajs.cn\r\nConnection: close\r\n\r\n");
110114
yield $ret = ngx_socket::recv(1024);
111115
yield ngx_socket::close();
112116
113117
var_dump($ret);
114118
';
115119
}
116120
121+
location = /ngx_var {
122+
set $a 1234567890;
123+
content_by_php '
124+
$a = ngx_var::get("a");
125+
var_dump($a);
126+
';
127+
}
128+
117129
}
118130
}
119131
```
120132

133+
Test
134+
----
135+
Using the perl of [Test::Nginx](https://github.com/openresty/test-nginx) module to testing, searching and finding out problem in ngx_php7.
136+
```sh
137+
ngx_php7 test ...
138+
nginx version: nginx/1.10.3
139+
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
140+
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_php7
141+
t/001-hello.t ........... ok
142+
t/002-ini.t ............. ok
143+
t/004-ngx_request.t ..... ok
144+
t/005-ngx_log.t ......... ok
145+
t/006-ngx_sleep.t ....... ok
146+
t/007-ngx_socket.t ...... ok
147+
t/008-ngx_exit.t ........ ok
148+
t/009-ngx_query_args.t .. ok
149+
t/010-ngx_post_args.t ... ok
150+
t/011-ngx_constants.t ... ok
151+
t/012-function.t ........ ok
152+
t/013-class.t ........... ok
153+
t/014-ngx_var.t ......... ok
154+
All tests successful.
155+
Files=13, Tests=28, 5 wallclock secs ( 0.05 usr 0.02 sys + 1.26 cusr 0.22 csys = 1.55 CPU)
156+
Result: PASS
157+
```
158+
159+
Directives
160+
----------
161+
* [php_ini_path](#php_ini_path)
162+
* [init_worker_by_php](#init_worker_by_php)
163+
* [rewrite_by_php](#rewrite_by_php)
164+
* [access_by_php](#access_by_php)
165+
* [content_by_php](#content_by_php)
166+
* [log_by_php](#log_by_php)
167+
* [header_filter_by_php](#header_filter_by_php)
168+
* [body_filter_by_php](#body_filter_by_php)
169+
170+
php_ini_path
171+
------------
172+
* **syntax:** `php_ini_path`_`<php.ini file path>`_
173+
* **context:** `http`
174+
* **phase:** `loading-config`
175+
176+
init_worker_by_php
177+
------------------
178+
* **syntax:** `init_worker_by_php`_`<php script code>`_
179+
* **context:** `http`
180+
* **phase:** `starting-worker`
181+
182+
rewrite_by_php
183+
--------------
184+
* **syntax:** `rewrite_by_php`_`<php script code>`_
185+
* **context:** `http, server, location, location if`
186+
* **phase:** `rewrite`
187+
188+
access_by_php
189+
-------------
190+
* **syntax:** `access_by_php`_`<php script code>`_
191+
* **context:** `http, server, location, location if`
192+
* **phase:** `access`
193+
194+
content_by_php
195+
--------------
196+
* **syntax:** `content_by_php`_`<php script code>`_
197+
* **context:** `http, server, location, location if`
198+
* **phase:** `content`
199+
200+
log_by_php
201+
----------
202+
* **syntax:** `log_by_php`_`<php script code>`_
203+
* **context:** `http, server, location, location if`
204+
* **phase:** `log`
205+
206+
header_filter_by_php
207+
--------------------
208+
* **syntax:** `header_filter_by_php`_`<php script code>`_
209+
* **context:** `http, server, location, location if`
210+
* **phase:** `output-header-filter`
211+
212+
body_filter_by_php
213+
------------------
214+
* **syntax:** `body_filter_by_php`_`<php script code>`_
215+
* **context:** `http, server, location, location if`
216+
* **phase:** `output-body-filter`
217+
218+
121219
Copyright and License
122220
---------------------
123221
```

config

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,74 @@
1-
ngx_addon_name=ngx_http_php_module
2-
HTTP_MODULES="$HTTP_MODULES ngx_http_php_module"
3-
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_php_module.c \
4-
$ngx_addon_dir/src/ngx_http_php_core.c \
5-
$ngx_addon_dir/src/ngx_http_php_directive.c \
6-
$ngx_addon_dir/src/ngx_http_php_handler.c \
7-
$ngx_addon_dir/src/ngx_http_php_request.c \
8-
$ngx_addon_dir/src/ngx_http_php_zend_uthread.c \
9-
$ngx_addon_dir/src/ngx_http_php_sleep.c \
10-
$ngx_addon_dir/src/ngx_http_php_socket.c \
11-
$ngx_addon_dir/src/ngx_http_php_util.c \
12-
$ngx_addon_dir/src/ngx_php_debug.c \
13-
$ngx_addon_dir/src/php/impl/php_ngx.c \
14-
$ngx_addon_dir/src/php/impl/php_ngx_test.c \
15-
$ngx_addon_dir/src/php/impl/php_ngx_track.c \
16-
$ngx_addon_dir/src/php/impl/php_ngx_core.c \
17-
$ngx_addon_dir/src/php/impl/php_ngx_log.c \
18-
$ngx_addon_dir/src/php/impl/php_ngx_request.c \
19-
$ngx_addon_dir/src/php/impl/php_ngx_generator.c \
20-
$ngx_addon_dir/src/php/impl/php_ngx_socket.c \
21-
"
22-
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_http_php_module.h \
23-
$ngx_addon_dir/src/ngx_http_php_core.h \
24-
$ngx_addon_dir/src/ngx_http_php_directive.h \
25-
$ngx_addon_dir/src/ngx_http_php_handler.h \
26-
$ngx_addon_dir/src/ngx_http_php_request.h \
27-
$ngx_addon_dir/src/ngx_http_php_zend_uthread.h \
28-
$ngx_addon_dir/src/ngx_http_php_sleep.h \
29-
$ngx_addon_dir/src/ngx_http_php_socket.h \
30-
$ngx_addon_dir/src/ngx_http_php_util.h \
31-
$ngx_addon_dir/src/ngx_php_debug.h \
32-
$ngx_addon_dir/src/php/impl/php_ngx.h \
33-
$ngx_addon_dir/src/php/impl/php_ngx_test.h \
34-
$ngx_addon_dir/src/php/impl/php_ngx_track.h \
35-
$ngx_addon_dir/src/php/impl/php_ngx_core.h \
36-
$ngx_addon_dir/src/php/impl/php_ngx_log.h \
37-
$ngx_addon_dir/src/php/impl/php_ngx_request.h \
38-
$ngx_addon_dir/src/php/impl/php_ngx_generator.h \
39-
$ngx_addon_dir/src/php/impl/php_ngx_socket.h \
40-
"
1+
ngx_addon_name=ngx_http_php7_module
412

42-
CORE_INCS="$CORE_INCS $PHP_INC $PHP_INC/main $PHP_INC/TSRM $PHP_INC/Zend $PHP_INC/ext $PHP_INC/ext/date/lib $PHP_INC/sapi/embed "
3+
NGX_PHP_SRCS="$ngx_addon_dir/src/ngx_http_php_module.c \
4+
$ngx_addon_dir/src/ngx_http_php_core.c \
5+
$ngx_addon_dir/src/ngx_http_php_directive.c \
6+
$ngx_addon_dir/src/ngx_http_php_handler.c \
7+
$ngx_addon_dir/src/ngx_http_php_request.c \
8+
$ngx_addon_dir/src/ngx_http_php_zend_uthread.c \
9+
$ngx_addon_dir/src/ngx_http_php_sleep.c \
10+
$ngx_addon_dir/src/ngx_http_php_socket.c \
11+
$ngx_addon_dir/src/ngx_http_php_util.c \
12+
$ngx_addon_dir/src/ngx_http_php_variable.c \
13+
$ngx_addon_dir/src/ngx_php_debug.c \
14+
$ngx_addon_dir/src/php/impl/php_ngx.c \
15+
$ngx_addon_dir/src/php/impl/php_ngx_test.c \
16+
$ngx_addon_dir/src/php/impl/php_ngx_track.c \
17+
$ngx_addon_dir/src/php/impl/php_ngx_core.c \
18+
$ngx_addon_dir/src/php/impl/php_ngx_log.c \
19+
$ngx_addon_dir/src/php/impl/php_ngx_request.c \
20+
$ngx_addon_dir/src/php/impl/php_ngx_generator.c \
21+
$ngx_addon_dir/src/php/impl/php_ngx_socket.c \
22+
$ngx_addon_dir/src/php/impl/php_ngx_var.c \
23+
"
24+
NGX_PHP_DEPS="$ngx_addon_dir/src/ngx_http_php_module.h \
25+
$ngx_addon_dir/src/ngx_http_php_core.h \
26+
$ngx_addon_dir/src/ngx_http_php_directive.h \
27+
$ngx_addon_dir/src/ngx_http_php_handler.h \
28+
$ngx_addon_dir/src/ngx_http_php_request.h \
29+
$ngx_addon_dir/src/ngx_http_php_zend_uthread.h \
30+
$ngx_addon_dir/src/ngx_http_php_sleep.h \
31+
$ngx_addon_dir/src/ngx_http_php_socket.h \
32+
$ngx_addon_dir/src/ngx_http_php_util.h \
33+
$ngx_addon_dir/src/ngx_http_php_variable.h \
34+
$ngx_addon_dir/src/ngx_php_debug.h \
35+
$ngx_addon_dir/src/php/impl/php_ngx.h \
36+
$ngx_addon_dir/src/php/impl/php_ngx_test.h \
37+
$ngx_addon_dir/src/php/impl/php_ngx_track.h \
38+
$ngx_addon_dir/src/php/impl/php_ngx_core.h \
39+
$ngx_addon_dir/src/php/impl/php_ngx_log.h \
40+
$ngx_addon_dir/src/php/impl/php_ngx_request.h \
41+
$ngx_addon_dir/src/php/impl/php_ngx_generator.h \
42+
$ngx_addon_dir/src/php/impl/php_ngx_socket.h \
43+
$ngx_addon_dir/src/php/impl/php_ngx_var.h \
44+
"
4345

44-
CORE_LIBS="$CORE_LIBS `$PHP_BIN/php-config --ldflags` -L$PHP_LIB -lphp7 `$PHP_BIN/php-config --libs` "
46+
if [ -z "$PHP_CONFIG" ]; then
47+
PHP_CONFIG=`which php-config`
48+
fi
4549

46-
#CORE_INCS="$CORE_INCS /usr/local/php72/include/php /usr/local/php72/include/php/main /usr/local/php72/include/php/TSRM /usr/local/php72/include/php/Zend /usr/local/php72/include/php/ext /usr/local/php72/include/php/ext/date/lib /usr/local/php72/include/php/sapi/embed "
50+
if [ -z "$NGX_PHP_INCS" ]; then
51+
NGX_PHP_INCS="`$PHP_CONFIG --includes | sed 's/-I//g'` `$PHP_CONFIG --include-dir`/sapi/embed "
52+
fi
53+
if [ -z "$NGX_PHP_LIBS" ]; then
54+
NGX_PHP_LIBS="`$PHP_CONFIG --ldflags` `$PHP_CONFIG --libs` -lphp7 "
55+
fi
4756

48-
#CORE_LIBS="$CORE_LIBS `/usr/local/php72/bin/php-config --ldflags` -L/usr/local/php72/lib -lphp7 `/usr/local/php72/bin/php-config --libs` "
57+
if [ $ngx_module_link = DYNAMIC ] ; then
58+
ngx_module_type=HTTP_AUX_FILTER
59+
ngx_module_name="ngx_http_php_module"
60+
ngx_module_srcs="$NGX_PHP_SRCS"
61+
ngx_module_deps="$NGX_PHP_DEPS"
62+
ngx_module_incs="$NGX_PHP_INCS"
63+
ngx_module_libs="$NGX_PHP_LIBS"
64+
65+
. auto/module
66+
else
67+
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_php_module"
68+
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $NGX_PHP_SRCS"
69+
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $NGX_PHP_DEPS"
70+
CORE_INCS="$CORE_INCS $NGX_PHP_INCS "
71+
CORE_LIBS="$CORE_LIBS $NGX_PHP_LIBS "
72+
fi
4973

5074
have=NDK_SET_VAR . auto/have

docs/hello_world_performance.png

198 KB
Loading

src/ngx_http_php_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright(c) 2016-2017 rryqszq4
2+
* Copyright(c) 2016-2018 rryqszq4
33
*
44
*
55
*/

src/ngx_http_php_core.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright(c) 2016-2017 rryqszq4
2+
* Copyright(c) 2016-2018 rryqszq4
33
*
44
*
55
*/
@@ -19,17 +19,17 @@
1919

2020
extern ngx_http_request_t *ngx_php_request;
2121

22-
typedef struct ngx_http_php_state_t {
22+
typedef struct ngx_http_php_state_s {
2323
unsigned php_init;
2424
unsigned php_shutdown;
2525
} ngx_http_php_state_t;
2626

27-
typedef enum code_type_t {
27+
typedef enum code_type_s {
2828
NGX_HTTP_PHP_CODE_TYPE_FILE,
2929
NGX_HTTP_PHP_CODE_TYPE_STRING
3030
} code_type_t;
3131

32-
typedef struct ngx_http_php_code_t {
32+
typedef struct ngx_http_php_code_s {
3333
union code {
3434
char *file;
3535
char *string;
@@ -48,18 +48,18 @@ typedef struct {
4848
} ngx_http_php_set_var_data_t;
4949
#endif
5050

51-
typedef struct ngx_http_php_rputs_chain_list_t {
51+
typedef struct ngx_http_php_rputs_chain_list_s {
5252
ngx_chain_t **last;
5353
ngx_chain_t *out;
5454
} ngx_http_php_rputs_chain_list_t;
5555

56-
typedef struct ngx_http_php_capture_node_t {
56+
typedef struct ngx_http_php_capture_node_s {
5757
ngx_str_t capture_uri;
5858
ngx_buf_t *capture_buf;
5959
ngx_str_t capture_str;
6060
} ngx_http_php_capture_node_t;
6161

62-
typedef struct ngx_http_php_ctx_t {
62+
typedef struct ngx_http_php_ctx_s {
6363
ngx_http_php_rputs_chain_list_t *rputs_chain;
6464
size_t body_length;
6565
ngx_str_t request_body_ctx;

0 commit comments

Comments
 (0)