12 use http\Message\Parser;
14 foreach (glob(__DIR__."/data/message_*.txt") as $file) {
16 $fd = fopen($file, "r") or die("Could not open $file");
18 switch ($parser->parse(fgets($fd), 0, $message)) {
19 case Parser::STATE_DONE:
20 $string = (string) $message;
22 case Parser::STATE_FAILURE:
23 throw new Exception(($e = error_get_last()) ? $e["message"] : "Could not parse $file");
31 switch ($parser->stream($fd, 0, $message)) {
32 case Parser::STATE_DONE:
33 case Parser::STATE_START:
36 printf("Expected parser state 0 or 8, got %d", $parser->getState());
38 if ($string !== (string) $message) {
39 $a = explode("\n", $string);
40 $b = explode("\n", (string) $message);
41 while ((null !== ($aa = array_shift($a))) || (null !== ($bb = array_shift($b)))) {
43 isset($aa) and printf("-- %s\n", $aa);
44 isset($bb) and printf("++ %s\n", $bb);