3 $php = getenv('TEST_PHP_EXECUTABLE');
5 define('PHP_BIN', $php);
6 } else if (defined('PHP_BINARY')) {
7 define('PHP_BIN', PHP_BINARY);
10 define("PHP_BIN", PHP_BINDIR.DIRECTORY_SEPARATOR."php");
13 foreach (array("raphf", "propro", "http") as $ext) {
14 if (!extension_loaded($ext)) {
15 switch (PHP_SHLIB_SUFFIX) {
20 dl($ext .".". PHP_SHLIB_SUFFIX);
26 /* stream_socket_server() automatically sets SO_REUSEADDR,
27 * which is, well, bad if the tests are run in parallel
29 $offset = rand(0,2000);
30 foreach (range(8000+$offset, 9000+$offset) as $port) {
31 if (($server = @stream_socket_server("tcp://localhost:$port"))) {
32 fprintf(STDERR, "%s\n", $port);
34 $R = array($server); $W = array(); $E = array();
35 $select = stream_select($R, $E, $E, 0, 10000);
36 if ($select && ($client = stream_socket_accept($server, 1))) {
37 if (getenv("PHP_HTTP_TEST_SSL")) {
38 stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
41 while (!feof($client)) {
44 } catch (Exception $ex) {
45 /* ignore disconnect */
46 if ($ex->getMessage() !== "Empty message received from stream") {
47 fprintf(STDERR, "%s\n", $ex);
52 } while ($select !== false);
58 function server($handler, $cb) {
59 $args = explode(' ', getenv('TEST_PHP_ARGS'));
60 $args[] = __DIR__."/$handler";
61 foreach ($args as $k => $v) {
62 if (!$v) unset($args[$k]);
64 proc(PHP_BIN, $args, $cb);
67 function nghttpd($cb) {
68 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
69 $offset = rand(0,2000);
70 foreach (range(8000+$offset, 9000+$offset) as $port) {
71 $comm = "exec nghttpd -d html $port http2.key http2.crt";
72 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
78 $status = proc_get_status($proc);
80 if (!$status["running"]) {
85 $cb($port, $stdin, $stdout, $stderr);
86 } catch (Exception $e) {
90 proc_terminate($proc);
100 function proc($bin, $args, $cb) {
101 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
102 $comm = escapeshellcmd($bin) . " ". implode(" ", array_map("escapeshellarg", $args));
103 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
109 $port = trim(fgets($stderr));
110 $R = array($stderr); $W = array(); $E = array();
111 } while (is_numeric($port) && stream_select($R, $W, $E, 0, 10000));
113 if (is_numeric($port)) {
115 $cb($port, $stdin, $stdout, $stderr);
116 } catch (Exception $e) {
121 proc_terminate($proc);