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 foreach (range(8000+PHP_INT_SIZE, 9000) as $port) {
15 if (($server = @stream_socket_server("tcp://localhost:$port"))) {
16 fprintf(STDERR, "%s\n", $port);
18 $R = array($server); $W = array(); $E = array();
19 $select = stream_select($R, $E, $E, 0, 10000);
20 if ($select && ($client = stream_socket_accept($server, 1))) {
21 if (getenv("PHP_HTTP_TEST_SSL")) {
22 stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
25 while (!feof($client)) {
28 } catch (Exception $ex) {
29 /* ignore disconnect */
30 if ($ex->getMessage() !== "Empty message received from stream") {
31 fprintf(STDERR, "%s\n", $ex);
36 } while ($select !== false);
42 function server($handler, $cb) {
43 $args = explode(' ', getenv('TEST_PHP_ARGS'));
44 $args[] = __DIR__."/$handler";
45 foreach ($args as $k => $v) {
46 if (!$v) unset($args[$k]);
48 proc(PHP_BIN, $args, $cb);
51 function nghttpd($cb) {
52 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
53 foreach (range(8000+PHP_INT_SIZE, 9000) as $port) {
54 $comm = "exec nghttpd -d html $port http2.key http2.crt";
55 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
61 $status = proc_get_status($proc);
63 if (!$status["running"]) {
68 $cb($port, $stdin, $stdout, $stderr);
69 } catch (Exception $e) {
73 proc_terminate($proc);
83 function proc($bin, $args, $cb) {
84 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
85 $comm = escapeshellcmd($bin) . " ". implode(" ", array_map("escapeshellarg", $args));
86 if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
92 $port = trim(fgets($stderr));
93 $R = array($stderr); $W = array(); $E = array();
94 } while (is_numeric($port) && stream_select($R, $W, $E, 0, 10000));
96 if (is_numeric($port)) {
98 $cb($port, $stdin, $stdout, $stderr);
99 } catch (Exception $e) {
104 proc_terminate($proc);