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");
14 /* stream_socket_server() automatically sets SO_REUSEADDR,
15 * which is, well, bad if the tests are run in parallel
17 $offset = rand(0,2000);
18 foreach (range(8000+$offset, 9000+$offset) as $port) {
19 if (($server = @stream_socket_server("tcp://localhost:$port"))) {
20 fprintf(STDERR, "%s\n", $port);
22 $R = array($server); $W = array(); $E = array();
23 $select = stream_select($R, $E, $E, 0, 10000);
24 if ($select && ($client = stream_socket_accept($server, 1))) {
25 if (getenv("PHP_HTTP_TEST_SSL")) {
26 stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
29 while (!feof($client)) {
32 } catch (Exception $ex) {
33 /* ignore disconnect */
34 if ($ex->getMessage() !== "Empty message received from stream") {
35 fprintf(STDERR, "%s\n", $ex);
40 } while ($select !== false);
46 function server($handler, $cb) {
47 $args = explode(' ', getenv('TEST_PHP_ARGS'));
48 $args[] = __DIR__."/$handler";
49 foreach ($args as $k => $v) {
50 if (!$v) unset($args[$k]);
52 proc(PHP_BIN, $args, $cb);
55 function nghttpd($cb) {
56 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
57 foreach (range(8000+PHP_INT_SIZE, 9000) as $port) {
58 $comm = "exec nghttpd -d html $port http2.key http2.crt";
59 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
65 $status = proc_get_status($proc);
67 if (!$status["running"]) {
72 $cb($port, $stdin, $stdout, $stderr);
73 } catch (Exception $e) {
77 proc_terminate($proc);
87 function proc($bin, $args, $cb) {
88 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
89 $comm = escapeshellcmd($bin) . " ". implode(" ", array_map("escapeshellarg", $args));
90 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
96 $port = trim(fgets($stderr));
97 $R = array($stderr); $W = array(); $E = array();
98 } while (is_numeric($port) && stream_select($R, $W, $E, 0, 10000));
100 if (is_numeric($port)) {
102 $cb($port, $stdin, $stdout, $stderr);
103 } catch (Exception $e) {
108 proc_terminate($proc);