summaryrefslogtreecommitdiff
path: root/test/it_url_server.php
blob: c832ee51803c73ba732303087f2860adc5958f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$host = 'localhost:' . rand(8000,8060);
$server = proc_open(
	"php -S $host -q " . dirname($_SERVER['PHP_SELF']) . '/it_url.testserver.php',
	array(0 => it::fopen('/dev/null', 'r'), 1 => it::fopen('/dev/null', 'w'), 2 => array('pipe', 'w')),
	$pipes
);
register_shutdown_function(
	function ($server) {
		proc_terminate($server);
	},
	$server
);

usleep(100000);
stream_set_blocking($pipes[2], 0);

function server_output()
{
	$result = array();
	while (($result[] = trim(fgets($GLOBALS['pipes'][2])))) {};
	return array_filter($result);
}

function handle_server($args)
{
	$res = true;
	foreach ((array)$args as $arg)
		$res = $res && $arg;
	$output = server_output();
	if (!$res)
		diag($output);
	else
		return $output;
}