]> granicus.if.org Git - php/blob
7dcc645422
[php] /
1 --TEST--
2 Test stream_set_timeout() function : error conditions
3 --FILE--
4 <?php
5 /* Prototype  : proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
6  * Description: Set timeout on stream read to seconds + microseonds
7  * Source code: ext/standard/streamsfuncs.c
8  * Alias to functions: socket_set_timeout
9  */
10
11 echo "*** Testing stream_set_timeout() : error conditions ***\n";
12
13 for ($i=0; $i<100; $i++) {
14   $port = rand(10000, 65000);
15   /* Setup socket server */
16   $server = @stream_socket_server("tcp://127.0.0.1:$port");
17   if ($server) {
18     break;
19   }
20 }
21 /* Connect to it */
22 $client = fsockopen("tcp://127.0.0.1:$port");
23
24 $seconds = 10;
25 $microseconds = 10;
26
27 echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
28 fclose($client);
29 try {
30     var_dump( stream_set_timeout($client, $seconds) );
31 } catch (TypeError $e) {
32     echo $e->getMessage(), "\n";
33 }
34
35 echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
36 $filestream = fopen(__FILE__, "r");
37 var_dump( stream_set_timeout($filestream, $seconds) );
38
39 fclose($filestream);
40 fclose($server);
41
42 echo "Done";
43 ?>
44 --EXPECTF--
45 *** Testing stream_set_timeout() : error conditions ***
46
47 -- Testing stream_set_timeout() function with a closed socket --
48 stream_set_timeout(): supplied resource is not a valid stream resource
49
50 -- Testing stream_set_timeout() function with a stream that does not support timeouts --
51 bool(false)
52 Done