Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with test node server
- Loading branch information
Showing
8 changed files
with
193 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# PHP HTTP/2 Server Push Example | ||
|
||
## What/Why | ||
|
||
This is a sample script to test a patch that adds support for curls new HTTP/2 server push support. | ||
|
||
It includes these instructions, a simple node.js HTTP/2 server with server push support and an example request (`node-server/index.js`) and the PHP script to test the new features. | ||
|
||
## Setup | ||
|
||
To run this example, you must first install `curl` 7.45.0 with HTTP/2 support. | ||
|
||
You can check this with `curl --version`, and make sure `http2` is listed (and that it's >= 7.4.50) | ||
|
||
If you use a mac, this can be done with homebrew: | ||
|
||
```sh | ||
$ brew install curl --with-nghttp2 --with-openssl | ||
``` | ||
|
||
You will also need node/npm >= 5.0: | ||
|
||
```sh | ||
$ brew install node | ||
``` | ||
|
||
Once you have this, you will need to compile PHP using the `curl-http2-push` branch in the `dshafik/php-src` fork. First clone the `php/php-src` repo: | ||
|
||
```sh | ||
$ git clone https://github.com/php/php-src.git | ||
``` | ||
|
||
Then add the fork, and check out the branch | ||
|
||
```sh | ||
$ git remote add dshafik https://github.com/dshafik/php-src.git | ||
$ git fetch --all | ||
$ git checkout dshafik/curl-http2-push | ||
``` | ||
|
||
Finally, compile PHP: | ||
|
||
```sh | ||
$ ./buildconf | ||
$ CFLAGS='-O0 -ggdb3' ./configure --disable-all --with-curl=/usr/local/Cellar/curl/7.45.0 --enable-debug | ||
$ make -j4 | ||
``` | ||
|
||
Once you've done this, you can execute `./sapi/cli/php` or `./sapi/phpdbg/phpdbg` with the patch, | ||
and compiled against the latest libcurl. | ||
|
||
Now, run the http2 server: | ||
|
||
```sh | ||
$ cd node-server | ||
$ npm install | ||
$ node index.js | ||
``` | ||
|
||
In another terminal, test it with `nghttp`: | ||
|
||
```sh | ||
$ nghttp -n --max-concurrent-streams=2 --stat http://127.0.0.1:3000/nghttp | ||
``` | ||
|
||
Finally, run the PHP script at the root of the checkout: | ||
|
||
```sh | ||
$ php ./push.php | ||
``` | ||
|
||
## Expected Behavior: | ||
It should spit out _at least_ some HTML, but preferably, some HTML and CSS (with the CSS being pushed) | ||
|
||
It should also show a `var_dump()` of the arguments passed to the closure. | ||
|
||
## Actual Behavior | ||
|
||
It doesn't dump any HTML, but it does `var_dump()`. It then displays an error: | ||
|
||
``` | ||
php(55493,0x7fff78e50300) malloc: *** error for object 0x10204ac00: pointer being freed was not allocated | ||
*** set a breakpoint in malloc_error_break to debug | ||
Program received signal SIGABRT, Aborted. | ||
0x00007fff8d188286 in __pthread_kill () from /usr/lib/system/libsystem_kernel.dylib | ||
``` | ||
|
||
## Other Tests | ||
|
||
Try it without setting the version to HTTP/2, and against another HTTP/2 enabled site, e.g. https://http2.akamai.net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICDTCCAXYCCQC7iiBVXeTv1DANBgkqhkiG9w0BAQUFADBLMQswCQYDVQQGEwJI | ||
VTETMBEGA1UECBMKU29tZS1TdGF0ZTETMBEGA1UEChMKbm9kZS1odHRwMjESMBAG | ||
A1UEAxMJbG9jYWxob3N0MB4XDTE0MTIwMjE4NDcwNFoXDTI0MTEyOTE4NDcwNFow | ||
SzELMAkGA1UEBhMCSFUxEzARBgNVBAgTClNvbWUtU3RhdGUxEzARBgNVBAoTCm5v | ||
ZGUtaHR0cDIxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOB | ||
jQAwgYkCgYEA8As7rj7xdD+RuAmORju9NI+jtOScGgiAbfovaFyzTu0O0H9SCExi | ||
u6e2iXMRfzomTix/yjRvbdHEXfgONG1MnKUc0oC4GxHXshyMDEXq9LadgAmR/nDL | ||
UVT0eo7KqC21ufaca2nVS9qOdlSCE/p7IJdb2+BF1RmuC9pHpXvFW20CAwEAATAN | ||
BgkqhkiG9w0BAQUFAAOBgQDn8c/9ho9L08dOqEJ2WTBmv4dfRC3oTWR/0oIGsaXb | ||
RhQONy5CJv/ymPYE7nCFWTMaia+w8oFqMie/aNZ7VK6L+hafuUS93IjuTXVN++JP | ||
4948B0BBagvXGTwNtvm/1sZHLrXTkH1dbRUEF8M+KUSRUu2zJgm+e1bD8WTKQOIL | ||
NA== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIICXQIBAAKBgQDwCzuuPvF0P5G4CY5GO700j6O05JwaCIBt+i9oXLNO7Q7Qf1II | ||
TGK7p7aJcxF/OiZOLH/KNG9t0cRd+A40bUycpRzSgLgbEdeyHIwMRer0tp2ACZH+ | ||
cMtRVPR6jsqoLbW59pxradVL2o52VIIT+nsgl1vb4EXVGa4L2kele8VbbQIDAQAB | ||
AoGAKKB+FVup2hb4PsG/RrvNphu5hWA721wdAIAbjfpCjtUocLlb1PO4sjIMfu7u | ||
wy3AVfLKHhsJ0Phz18OoA8+L65NMoMRsHOGaLEnGIJzJcnDLT5+uTFN5di0a1+UK | ||
BzB828rlHBNoQisogVCoKTYlCPJAZuI3trEzupWAV28XjTECQQD5LUEwYq4xr62L | ||
dEq5Qj/+c5paK/jrEBY83VZUmWzYsFgUwmpdku2ITRILQlOM33j6rk8krZZb93sb | ||
38ydmfwjAkEA9p30zyjOI9kKqTl9WdYNYtIXpyNGYa+Pga33o9pawTewiyS2uCYs | ||
wnQQV26bQ0YwQqLQhtIbo4fzCO6Ex0w7LwJBANHNbd8cp4kEX35U+3nDM3i+w477 | ||
CUp6sA6tWrw+tqw4xuEr1T1WshOauP+r6AdsPkPsMo0yb7CdzxVoObPVbLsCQQCc | ||
sx0cjEb/TCeUAy186Z+zzN6umqFb7Jt4wLt7Z4EHCIWqw/c95zPFks3XYDZTdsOv | ||
c5igMdzR+c4ZPMUthWiNAkByx7If12G1Z/R2Y0vIB0WJq4BJnZCZ0mRR0oAmPoA+ | ||
sZbmwctZ3IU+68Rgr4EAhrU04ygjF67IiNyXX0qqu3VH | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var h2 = require('http2'); | ||
var fs = require('fs'); | ||
var log = require('bunyan').createLogger({name: 'server'}); | ||
|
||
var options = { | ||
key: fs.readFileSync('./cert/localhost.key'), | ||
cert: fs.readFileSync('./cert/localhost.crt') | ||
}; | ||
|
||
var server = h2.createServer(options, function(req, res) { | ||
console.log(req); | ||
if (req.url != '/main.js' && res.push) { | ||
var push = res.push('/main.js'); | ||
push.writeHead(200); | ||
push.end('alert("hello from push stream!")'); | ||
} | ||
|
||
res.writeHead(200); | ||
res.end('Hello World! <script src="/main.js"></script>'); | ||
}); | ||
|
||
server.listen(8080, "0.0.0.0"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "node-h2-push-server-example", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Davey Shafik <dshafik@akamai.com>", | ||
"license": "Apache 2.0", | ||
"dependencies": { | ||
"bunyan": "^1.5.1", | ||
"http2": "^3.2.0" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
$callback = function() { | ||
$args = func_get_args(); | ||
var_dump($args); | ||
var_dump(CURL_PUSH_OK); | ||
return CURL_PUSH_OK; | ||
}; | ||
|
||
$mh = curl_multi_init(); | ||
|
||
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback); | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $_SERVER['argv'][1]); | ||
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3); | ||
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); | ||
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); | ||
|
||
curl_multi_add_handle($mh, $ch); | ||
|
||
$active = null; | ||
//execute the handles | ||
do { | ||
$mrc = curl_multi_exec($mh, $active); | ||
} while ($mrc == CURLM_CALL_MULTI_PERFORM); | ||
|
||
while ($active && $mrc == CURLM_OK) { | ||
if (curl_multi_select($mh) != -1) { | ||
do { | ||
$mrc = curl_multi_exec($mh, $active); | ||
} while ($mrc == CURLM_CALL_MULTI_PERFORM); | ||
} | ||
} | ||
|
||
curl_multi_close($mh); |