1--TEST--
2Test 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
11echo "*** Testing stream_set_timeout() : error conditions ***\n";
12
13//Test stream_set_timeout with one more than the expected number of arguments
14echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n";
15
16for ($i=0; $i<100; $i++) {
17  $port = rand(10000, 65000);
18  /* Setup socket server */
19  $server = @stream_socket_server("tcp://127.0.0.1:$port");
20  if ($server) {
21    break;
22  }
23}
24/* Connect to it */
25$client = fsockopen("tcp://127.0.0.1:$port");
26
27$seconds = 10;
28$microseconds = 10;
29$extra_arg = 10;
30var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) );
31
32// Testing stream_set_timeout with one less than the expected number of arguments
33echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n";
34
35$seconds = 10;
36var_dump( stream_set_timeout($client) );
37
38
39echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
40fclose($client);
41var_dump( stream_set_timeout($client, $seconds) );
42
43echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n";
44var_dump( stream_set_timeout($seconds, $seconds) );
45
46echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
47$filestream = fopen(__FILE__, "r");
48var_dump( stream_set_timeout($filestream, $seconds) );
49
50fclose($filestream);
51fclose($server);
52
53echo "Done";
54?>
55--EXPECTF--
56*** Testing stream_set_timeout() : error conditions ***
57
58-- Testing stream_set_timeout() function with more than expected no. of arguments --
59
60Warning: stream_set_timeout() expects at most 3 parameters, 4 given in %s on line %i
61NULL
62
63-- Testing stream_set_timeout() function with less than expected no. of arguments --
64
65Warning: stream_set_timeout() expects at least 2 parameters, 1 given in %s on line %i
66NULL
67
68-- Testing stream_set_timeout() function with a closed socket --
69
70Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i
71bool(false)
72
73-- Testing stream_set_timeout() function with an invalid stream --
74
75Warning: stream_set_timeout() expects parameter 1 to be resource, integer given in %s on line %i
76NULL
77
78-- Testing stream_set_timeout() function with a stream that does not support timeouts --
79bool(false)
80Done
81