1--TEST--
2Test fsockopen() function : basic functionality
3--FILE--
4<?php
5echo "*** Testing fsockopen() : basic functionality ***\n";
6
7echo "Open a server socket\n";
8
9for ($i=0; $i<100; $i++) {
10  $port = rand(10000, 65000);
11  /* Setup socket server */
12  $server = @stream_socket_server("tcp://127.0.0.1:$port");
13  if ($server) {
14    break;
15  }
16}
17
18// Initialise all required variables
19$hostname = 'tcp://127.0.0.1'; // loopback address
20$errno = null;
21$errstr = null;
22$timeout = 1.5;
23
24echo "\nCalling fsockopen() with all possible arguments:\n";
25$client = fsockopen($hostname, $port, $errno, $errstr, $timeout);
26var_dump($client);
27fclose($client);
28
29echo "\nCalling fsockopen() with mandatory arguments:\n";
30$second_client = fsockopen($hostname, $port);
31var_dump($second_client);
32fclose($second_client);
33
34echo "\nCalling fsockopen() with address and port in same string:\n";
35$address = $hostname . ':' . $port;
36$third_client = fsockopen($address);
37var_dump($third_client);
38fclose($third_client);
39
40echo "Done";
41?>
42--EXPECTF--
43*** Testing fsockopen() : basic functionality ***
44Open a server socket
45
46Calling fsockopen() with all possible arguments:
47resource(%d) of type (stream)
48
49Calling fsockopen() with mandatory arguments:
50resource(%d) of type (stream)
51
52Calling fsockopen() with address and port in same string:
53resource(%d) of type (stream)
54Done
55