1--TEST--
2Test fsockopen() function : error conditions
3--FILE--
4<?php
5/* Prototype  : proto resource fsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
6 * Description: Open Internet or Unix domain socket connection
7 * Source code: ext/standard/fsock.c
8 * Alias to functions:
9 */
10
11
12echo "*** Testing fsockopen() : basic error conditions ***\n";
13
14
15echo "\n-- Testing fsockopen() function with more than expected no. of arguments --\n";
16$hostname = 'string_val';
17$port = 10;
18$errno = 10;
19$errstr = 'string_val';
20$timeout = 10.5;
21$extra_arg = 10;
22var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout, $extra_arg) );
23var_dump($errstr);
24var_dump($errno);
25
26echo "\n-- Testing fsockopen() function with less than expected no. of arguments --\n";
27var_dump( fsockopen() );
28
29echo "\n-- Attempting to connect to a non-existent socket --\n";
30$hostname = 'tcp://127.0.0.1'; // loopback address
31$port = 31337;
32$errno = null;
33$errstr = null;
34$timeout = 1.5;
35var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) );
36var_dump($errstr);
37
38echo "\n-- Attempting to connect using an invalid protocol --\n";
39$hostname = 'invalid://127.0.0.1'; // loopback address
40$port = 31337;
41$errno = null;
42$errstr = null;
43$timeout = 1.5;
44var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) );
45var_dump($errstr);
46
47echo "Done";
48?>
49--EXPECTF--
50*** Testing fsockopen() : basic error conditions ***
51
52-- Testing fsockopen() function with more than expected no. of arguments --
53
54Warning: fsockopen() expects at most 5 parameters, 6 given in %s on line %d
55bool(false)
56string(10) "string_val"
57int(10)
58
59-- Testing fsockopen() function with less than expected no. of arguments --
60
61Warning: fsockopen() expects at least 1 parameter, 0 given in %s on line %d
62bool(false)
63
64-- Attempting to connect to a non-existent socket --
65
66Warning: fsockopen(): unable to connect to tcp://127.0.0.1:31337 (%a) in %s on line %d
67bool(false)
68string(%d) "%a"
69
70-- Attempting to connect using an invalid protocol --
71
72Warning: fsockopen(): unable to connect to invalid://127.0.0.1:31337 (Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?) in %s on line %d
73bool(false)
74string(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?"
75Done
76