ServerClientTestCase::getInstance()->notify($worker);
}
-function phpt_wait($worker = WORKER_DEFAULT_NAME)
+function phpt_wait($worker = WORKER_DEFAULT_NAME, $timeout = null)
{
- ServerClientTestCase::getInstance()->wait($worker);
+ ServerClientTestCase::getInstance()->wait($worker, $timeout);
}
/**
}
}
- public function wait($worker)
+ public function wait($worker, $timeout = null)
{
- fgets($this->isWorker ? STDIN : $this->workerStdOut[$worker]);
+ $handle = $this->isWorker ? STDIN : $this->workerStdOut[$worker];
+ if ($timeout === null) {
+ fgets($handle);
+ return true;
+ }
+
+ stream_set_blocking($handle, false);
+ $read = [$handle];
+ $result = stream_select($read, $write, $except, $timeout);
+ if (!$result) {
+ return false;
+ }
+
+ fgets($handle);
+ stream_set_blocking($handle, true);
+ return true;
}
public function notify($worker)
$read = [$fp];
$buf = '';
- $printed = false;
+ $warmedUp = false;
while (stream_select($read, $write, $except, 1000)) {
$chunk = stream_get_contents($fp, 4096);
- if ($chunk !== "") {
- var_dump($chunk);
- $buf .= $chunk;
- } elseif (!$printed) {
- $printed = true;
- var_dump($chunk);
+ $buf .= $chunk;
+ phpt_notify('proxy');
+ if (!$warmedUp) {
+ if ($buf !== 'warmup') {
+ continue;
+ }
+ $warmedUp = true;
+ $buf = '';
+ phpt_notify('server');
+ continue;
}
+ var_dump($chunk);
if ($buf === 'hello, world') {
break;
}
phpt_notify();
$conn = stream_socket_accept($fp);
+ fwrite($conn, 'warmup');
+ phpt_wait();
fwrite($conn, 'hello, world');
phpt_wait();
$parts = str_split($data, (int) ceil(strlen($data) / 3));
foreach ($parts as $part) {
fwrite($conn, $part);
- usleep(1000);
+ phpt_wait(null, 1);
}
} else {
fwrite($conn, $data);
?>
--EXPECT--
string(0) ""
+string(0) ""
string(12) "hello, world"