Skip to content

Commit

Permalink
Add Dockerfile for replication
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafik committed Nov 21, 2015
1 parent d0cd1d9 commit 9e507e6
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 143 deletions.
62 changes: 62 additions & 0 deletions Dockerfile
@@ -0,0 +1,62 @@
FROM ubuntu:15.10
MAINTAINER Davey Shafik <dshafik@akamai.com>

RUN apt-get update
RUN apt-get install --yes build-essential bison wget
RUN apt-get install --yes git
RUN set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done

ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 5.0.0
RUN apt-get install --yes curl
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --verify SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - \
&& tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
&& rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc
RUN apt-get remove --yes curl

RUN apt-get build-dep --yes curl
RUN apt-get install --yes g++ make binutils autoconf automake autotools-dev libtool pkg-config \
zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \
libjemalloc-dev

ENV CFLAGS -O0 -ggdb3

RUN git clone https://github.com/tatsuhiro-t/nghttp2.git
WORKDIR nghttp2
RUN git checkout v1.4.0
RUN autoreconf -i && automake && autoconf && ./configure && make && make install
WORKDIR ..

RUN git clone https://github.com/bagder/curl.git
WORKDIR curl
RUN ./buildconf && ./configure --with-nghttp2 --with-ssl --enable-debug
RUN make && make install
WORKDIR ..
RUN git clone https://github.com/dshafik/php-src.git
WORKDIR php-src
RUN git checkout curl-http2-push && ./buildconf && ./configure --disable-all --enable-debug --with-curl && make
WORKDIR ..
RUN git clone https://github.com/dshafik/php-http2-push-example.git
RUN git clone https://github.com/bagder/curl-http2-dev.git
ENV LD_LIBRARY_PATH /usr/local/lib
RUN apt-get install --yes vim gdb
ENV SHEBANG '#!/bin/bash'
RUN echo $SHEBANG > ./run.sh
RUN echo "nghttpd --htdocs=./curl-http2-dev --verbose --echo-upload --push=/index.html=/LICENSE --push=/index.html=/README.md 8443 ./curl-http2-dev/privkey.pem ./curl-http2-dev/server.pem &" >> ./run.sh
RUN echo "sleep 2" >> ./run.sh
RUN echo "./php-src/sapi/cli/php ./php-http2-push-example/push.php https://localhost:8443/index.html" >> ./run.sh
RUN chmod +x ./run.sh
CMD echo "Running" && ./run.sh
74 changes: 17 additions & 57 deletions README.md
Expand Up @@ -2,89 +2,49 @@

## 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.
This is a sample script/docker container build to test a patch that adds support for curls new HTTP/2 server push support.

## 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)
### Docker

If you use a mac, this can be done with homebrew:
Build and run the docker container:

```sh
$ brew install curl --with-nghttp2 --with-openssl
$ docker build -t $USER/php-http2-push-example .
$ docker run $USER/php-http2-push-example
```

You will also need node/npm >= 5.0:

```sh
$ brew install node
```
To debug it yourself:

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:
Start the docker container:

```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
$ docker run -ti $USER/php-http2-push-example /bin/bash
```

Finally, compile PHP:
Run nghttpd inside the container from a different terminal:

```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
$ docker run -ti $USER/php-http2-push-example nghttpd --htdocs=./curl-http2-dev --verbose --echo-upload --push=/index.html=/LICENSE --push=/index.html=/README.md 8443 ./curl-http2-dev/privkey.pem ./curl-http2-dev/server.pem
```

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:
Run gdb:

```sh
$ php ./push.php
```
$ gdb --args php-src/sapi/cli/php ./php-http2-push-example/push.php https://localhost:8443/index.html
gdb> run
```

## Expected Behavior:
It should spit out _at least_ some HTML, but preferably, some HTML and CSS (with the CSS being pushed)
It should spit out three documents, and show a bunch of nghttpd output either intermingle, or if you're
debugging it yourself, then the nghttpd output will be in the second terminal.

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
```
This currently works as expected except for some memory leaks

## Other Tests

Expand Down
1 change: 0 additions & 1 deletion node-server/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions node-server/cert/localhost.crt

This file was deleted.

15 changes: 0 additions & 15 deletions node-server/cert/localhost.key

This file was deleted.

23 changes: 0 additions & 23 deletions node-server/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions node-server/package.json

This file was deleted.

42 changes: 25 additions & 17 deletions push.php
@@ -1,35 +1,43 @@
<?php
$callback = function() {
$args = func_get_args();
var_dump($args);
var_dump(CURL_PUSH_OK);
$transfers = 1;

$callback = function() use (&$transfers) {
$transfers++;
return CURL_PUSH_OK;
};

$mh = curl_multi_init();

curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
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_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

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);
}
}
$status = curl_multi_exec($mh, $active);

do {
$info = curl_multi_info_read($mh);
if (false !== $info && $info['msg'] == CURLMSG_DONE) {
$handle = $info['handle'];
if ($handle !== null) {
$transfers--;
$out = curl_multi_getcontent($info['handle']);
var_dump($out);
curl_multi_remove_handle($mh, $handle);
curl_close($handle);
}
}
} while ($info);
} while ($transfers);

curl_multi_close($mh);

0 comments on commit 9e507e6

Please sign in to comment.