xref: /PHP-8.1/ext/standard/tests/streams/gh8409.phpt (revision b8d07451)
1--TEST--
2GH-8409: Error in socket creation when error handler does not clean persistent connection
3--FILE--
4<?php
5set_error_handler(function (int $errno, string $errstring): never {
6    trigger_error($errstring, E_USER_ERROR);
7});
8
9register_shutdown_function(function (): void {
10    foreach (get_resources() as $res) {
11        if (get_resource_type($res) === 'persistent stream') {
12            echo "ERROR: persistent stream not closed\n";
13            return;
14        }
15    }
16    echo "OK: persistent stream closed\n";
17});
18
19stream_socket_client('tcp://9999.9999.9999.9999:9999', $error_code, $error_message, 0.2, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
20
21echo "ERROR: this should not be visible\n";
22?>
23--EXPECTF--
24Fatal error: stream_socket_client(): %s in %sgh8409.php on line %d
25OK: persistent stream closed
26