From fc41aeed0050dee80c86e7450f2e6aea592a6aaa Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 29 Oct 2026 13:50:21 +0000 Subject: [PATCH] Create mysqli_real_connect_compression.phpt --- .../mysqli_real_connect_compression.phpt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ext/mysqli/tests/mysqli_real_connect_compression.phpt diff --git a/ext/mysqli/tests/mysqli_real_connect_compression.phpt b/ext/mysqli/tests/mysqli_real_connect_compression.phpt new file mode 100644 index 000000000000..c87099b0a3d0 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_connect_compression.phpt @@ -0,0 +1,56 @@ +--TEST-- +MYSQLI_CLIENT_COMPRESS compresses the data in both directions +--EXTENSIONS-- +mysqli +--SKIPIF-- +info(); +if (!str_contains(ob_get_clean(), 'Compression => supported')) { + die('skip mysqlnd is built without compression support'); +} +?> +--FILE-- +query("SHOW SESSION STATUS WHERE Variable_name IN ('Bytes_received', 'Bytes_sent')"); + return array_map(intval(...), array_column($result->fetch_all(), 1, 0)); +} + +$size = 100000; + +foreach ([0 => 'Uncompressed', MYSQLI_CLIENT_COMPRESS => 'Compressed'] as $flags => $label) { + $link = mysqli_init(); + if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags, false)) { + printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + continue; + } + + $before = server_bytes($link); + $link->query("DO '" . str_repeat('x', $size) . "'"); + $after_send = server_bytes($link); + $row = $link->query("SELECT REPEAT('x', $size)")->fetch_row(); + $after_receive = server_bytes($link); + + $client_to_server = $after_send['Bytes_received'] - $before['Bytes_received']; + $server_to_client = $after_receive['Bytes_sent'] - $after_send['Bytes_sent']; + + echo "$label:\n"; + printf(" client to server is compressed: %s\n", $client_to_server < $size / 10 ? 'yes' : 'no'); + printf(" server to client is compressed: %s\n", $server_to_client < $size / 10 ? 'yes' : 'no'); + printf(" result is correct: %s\n", $row[0] === str_repeat('x', $size) ? 'yes' : 'no'); +} +?> +--EXPECT-- +Uncompressed: + client to server is compressed: no + server to client is compressed: no + result is correct: yes +Compressed: + client to server is compressed: yes + server to client is compressed: yes + result is correct: yes