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