4 require __DIR__ . '/../../util/server_tests.inc';
5 ServerUtilServerTests::$LOG_ROOT = '/tmp/hhvm_server';
6 require __DIR__ . '/../Adoy/Client.php';
8 ServerUtilServerTests::$DOC_ROOT = dirname(__DIR__).'/server_root';
9 ServerUtilServerTests::$request = fun('fastcgi_request');
12 function runTest($testController, $customArgs = '') {
13 $pid = posix_getpid();
15 $serverProc = $serverPort = $adminPort = null;
17 $serverProc = startServer(inout $serverPort, inout $adminPort, inout $debugPort,
18 dirname(__DIR__), ServerUtilServerTests::$DOC_ROOT, $customArgs);
19 $testController($serverPort);
20 stopServer($adminPort, $serverProc);
21 } catch (Exception $e) {
22 error_log("Caught exception, test failed, pid=$pid, exn=".$e->getMessage());
24 if ($serverProc) proc_close($serverProc);
25 error_log('test failed');
29 function fastcgi_request($host, $port, $path, $post = darray[], $headers = darray[], $extra_args = darray[]) {
31 $client = new \Adoy\FastCGI\Client($host, $port);
32 $content = http_build_query($post);
34 $args = array_merge(darray[
35 'GATEWAY_INTERFACE' => 'FastCGI/1.0',
36 'REQUEST_METHOD' => (!($post ?? false)) ? 'GET' : 'POST',
37 'SERVER_SOFTWARE' => 'php/fcgiclient',
38 'SERVER_PROTOCOL' => 'HTTP/1.1',
39 'CONTENT_LENGTH' => strlen($content)
41 foreach($headers as $k => $v) {
42 $args["HTTP_" . strtoupper($k)] = $v;
44 $pos = strpos($path, '?');
46 $args['QUERY_STRING'] = substr($path, $pos + 1);
47 $path = substr($path, 0, $pos);
49 $doc_root = ServerUtilServerTests::$DOC_ROOT;
50 $pos = strpos($path, '//');
52 $doc_root .= '/' . substr($path, 0, $pos);
53 $path = substr($path, $pos + 2);
55 $args['SCRIPT_FILENAME'] = $doc_root . '/' . $path;
56 $args['SCRIPT_NAME'] = $path;
57 $args['DOCUMENT_ROOT'] = $doc_root;
59 @$result = $client->request($args, $content);
61 $pos = strpos($result, "\r\n\r\n");
63 $result = substr($result, $pos + 4);
66 } catch (Exception $e) {
67 tlog("request exception: " . $e->getMessage() .'('.$e->getTraceAsString().')');