xref: /PHP-7.2/ext/sockets/tests/socket_bind.phpt (revision f1d7e3ca)
1--TEST--
2ext/sockets - socket_bind - basic test
3--CREDITS--
4Florian Anderiasch
5fa@php.net
6--SKIPIF--
7<?php
8    if (!extension_loaded('sockets')) {
9        die('skip - sockets extension not available.');
10    }
11    if (getenv("SKIP_ONLINE_TESTS")) {
12        die("skip test requiring internet connection");
13    }
14?>
15--FILE--
16<?php
17    $rand = rand(1,999);
18    $s_c     = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
19    $s_bind  = socket_bind($s_c, '0.0.0.0', 31330+$rand);
20    var_dump($s_bind);
21
22    // Connect to destination address
23    $s_conn  = socket_connect($s_c, 'www.php.net', 80);
24    var_dump($s_conn);
25
26    // Write
27    $request = 'GET / HTTP/1.1' . "\r\n";
28    $s_write = socket_write($s_c, $request);
29    var_dump($s_write);
30
31    // Close
32    $s_close = socket_close($s_c);
33    var_dump($s_close);
34?>
35--EXPECTF--
36bool(true)
37bool(true)
38int(16)
39NULL
40