- $comm = sprintf("%s %s/%s", PHP_BINARY, __DIR__, $handler);
- if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
- $port = trim(fgets($pipes[2]));
+ foreach (range(8000, 9000) as $port) {
+ $comm = "exec nghttpd -d html $port http2.key http2.crt";
+ if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
+ $stdin = $pipes[0];
+ $stdout = $pipes[1];
+ $stderr = $pipes[2];
+
+ usleep(50000);
+ $status = proc_get_status($proc);
+
+ if (!$status["running"]) {
+ continue;
+ }
+
+ try {
+ $cb($port, $stdin, $stdout, $stderr);
+ } catch (Exception $e) {
+ echo $e,"\n";
+ }