1--TEST-- 2http:// and ignore_errors 3--INI-- 4allow_url_fopen=1 5--SKIPIF-- 6<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> 7--FILE-- 8<?php 9require 'server.inc'; 10 11function do_test($context_options) { 12 13 $context = stream_context_create(array('http' => $context_options)); 14 15 $responses = array( 16 "data://text/plain,HTTP/1.0 200 Ok\r\nX-Foo: bar\r\n\r\n1", 17 "data://text/plain,HTTP/1.0 404 Not found\r\nX-bar: baz\r\n\r\n2", 18 ); 19 20 $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); 21 22 foreach($responses as $r) { 23 24 $fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context); 25 var_dump($fd); 26 27 if ($fd) { 28 $meta_data = stream_get_meta_data($fd); 29 var_dump($meta_data['wrapper_data']); 30 31 var_dump(stream_get_contents($fd)); 32 } 33 34 fseek($output, 0, SEEK_SET); 35 var_dump(stream_get_contents($output)); 36 fseek($output, 0, SEEK_SET); 37 } 38 39 http_server_kill($pid); 40} 41 42echo "-- Test: requests without ignore_errors --\n"; 43 44do_test(array()); 45 46echo "-- Test: requests with ignore_errors --\n"; 47 48do_test(array('ignore_errors' => true)); 49 50echo "-- Test: requests with ignore_errors (2) --\n"; 51 52do_test(array('ignore_errors' => 1)); 53 54?> 55--EXPECTF-- 56-- Test: requests without ignore_errors -- 57resource(%d) of type (stream) 58array(2) { 59 [0]=> 60 string(15) "HTTP/1.0 200 Ok" 61 [1]=> 62 string(10) "X-Foo: bar" 63} 64string(1) "1" 65string(48) "GET /foo/bar HTTP/1.0 66Host: 127.0.0.1:12342 67 68" 69 70Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: HTTP request failed! HTTP/1.0 404 Not found 71 in %s on line %d 72bool(false) 73string(48) "GET /foo/bar HTTP/1.0 74Host: 127.0.0.1:12342 75 76" 77-- Test: requests with ignore_errors -- 78resource(%d) of type (stream) 79array(2) { 80 [0]=> 81 string(15) "HTTP/1.0 200 Ok" 82 [1]=> 83 string(10) "X-Foo: bar" 84} 85string(1) "1" 86string(48) "GET /foo/bar HTTP/1.0 87Host: 127.0.0.1:12342 88 89" 90resource(%d) of type (stream) 91array(2) { 92 [0]=> 93 string(22) "HTTP/1.0 404 Not found" 94 [1]=> 95 string(10) "X-bar: baz" 96} 97string(1) "2" 98string(48) "GET /foo/bar HTTP/1.0 99Host: 127.0.0.1:12342 100 101" 102-- Test: requests with ignore_errors (2) -- 103resource(%d) of type (stream) 104array(2) { 105 [0]=> 106 string(15) "HTTP/1.0 200 Ok" 107 [1]=> 108 string(10) "X-Foo: bar" 109} 110string(1) "1" 111string(48) "GET /foo/bar HTTP/1.0 112Host: 127.0.0.1:12342 113 114" 115resource(%d) of type (stream) 116array(2) { 117 [0]=> 118 string(22) "HTTP/1.0 404 Not found" 119 [1]=> 120 string(10) "X-bar: baz" 121} 122string(1) "2" 123string(48) "GET /foo/bar HTTP/1.0 124Host: 127.0.0.1:12342 125 126" 127