Skip to content

Commit a8f1613

Browse files
committed
change test to non online
1 parent 1998184 commit a8f1613

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
--TEST--
22
Testing linger `socket` option.
3-
--SKIPIF--
4-
<?php
5-
//if (getenv("SKIP_ONLINE_TESTS")) die('skip online test');
6-
if (!in_array('https', stream_get_wrappers())) die('skip: https wrapper is required');
7-
?>
83
--FILE--
94
<?php
5+
for ($i=0; $i<100; $i++) {
6+
$port = rand(10000, 65000);
7+
/* Setup socket server */
8+
$server = @stream_socket_server("tcp://127.0.0.1:$port");
9+
if ($server) {
10+
break;
11+
}
12+
}
13+
$client = stream_socket_client("tcp://127.0.0.1:$port");
1014
$context = stream_context_create(['socket' => ['linger' => false]]);
11-
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false);
15+
$socket = stream_socket_client("tcp://127.0.0.1:$port", $errno, $errstr, 0, STREAM_CLIENT_CONNECT, $context);
16+
var_dump($socket);
1217
$context = stream_context_create(['socket' => ['linger' => PHP_INT_MAX + 1]]);
13-
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false);
14-
$context = stream_context_create(['socket' => ['linger' => 3]]);
15-
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false);
18+
$socket = stream_socket_client("tcp://127.0.0.1:$port", $errno, $errstr, 0, STREAM_CLIENT_CONNECT, $context);
19+
var_dump($socket);
20+
$context = stream_context_create(['socket' => ['linger' => 5]]);
21+
$socket = stream_socket_client("tcp://127.0.0.1:$port", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $context);
22+
var_dump($socket);
23+
stream_set_blocking($socket, true);
24+
var_dump(stream_socket_sendto($socket, "data"));
25+
$data = base64_decode("1oIBAAABAAAAAAAAB2V4YW1wbGUDb3JnAAABAAE=");
26+
stream_set_blocking($socket, 0);
27+
stream_socket_sendto($socket, $data);
28+
stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
29+
stream_socket_shutdown($server, STREAM_SHUT_RDWR);
1630
?>
1731
--EXPECTF--
18-
Warning: file_get_contents(https://httpbin.org/get): Failed to open stream: Invalid `linger` value in %s on line %d
32+
Warning: stream_socket_client(): Unable to connect to tcp://127.0.0.1:%d (Invalid `linger` value) in %s on line %d
1933
bool(false)
2034

21-
Warning: file_get_contents(https://httpbin.org/get): Failed to open stream: Invalid `linger` value in %s on line %d
35+
Warning: stream_socket_client(): Unable to connect to tcp://127.0.0.1:%d (Invalid `linger` value) in %s on line %d
2236
bool(false)
23-
bool(true)
37+
resource(%d) of type (stream)
38+
iunt(4)

0 commit comments

Comments
 (0)