fsockopen_basic.phpt 1.6 KB

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