1--TEST-- 2mysqli_get_client_stats() - PS 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?PHP 7require_once 'skipifconnectfailure.inc'; 8if (!function_exists('mysqli_get_client_stats')) { 9 die("skip only available with mysqlnd"); 10} 11?> 12--INI-- 13mysqlnd.collect_statistics=1 14mysqlnd.collect_memory_statistics=1 15--FILE-- 16<?php 17 require_once 'connect.inc'; 18 require_once 'table.inc'; 19 20 $stats = mysqli_get_client_stats(); 21 printf("BEGINNING: rows_fetched_from_client_ps_unbuffered = %d\n", $stats['rows_fetched_from_client_ps_unbuffered']); 22 printf("BEGINNING: rows_fetched_from_client_ps_buffered = %d\n", $stats['rows_fetched_from_client_ps_buffered']); 23 printf("BEGINNING: rows_fetched_from_client_ps_cursor = %d\n", $stats['rows_fetched_from_client_ps_cursor']); 24 25 if (!$stmt = mysqli_stmt_init($link)) 26 printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 27 28 $id = null; 29 if (!mysqli_stmt_prepare($stmt, 'SELECT id FROM test') || 30 !mysqli_stmt_execute($stmt) || 31 !mysqli_stmt_store_result($stmt) || 32 !mysqli_stmt_bind_result($stmt, $id)) 33 printf("[002] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 34 35 $num_rows = 0; 36 while (mysqli_stmt_fetch($stmt)) 37 $num_rows++; 38 39 mysqli_stmt_free_result($stmt); 40 41 $after = mysqli_get_client_stats(); 42 43 if ($after['rows_fetched_from_client_ps_unbuffered'] != $stats['rows_fetched_from_client_ps_unbuffered']) 44 printf("[003] Unbuffered rows got increased after buffered PS, expecting %d got %d.\n", 45 $stats['rows_fetched_from_client_ps_unbuffered'], 46 $after['rows_fetched_from_client_ps_unbuffered']); 47 48 $stats['rows_fetched_from_client_ps_buffered'] += $num_rows; 49 if ($after['rows_fetched_from_client_ps_buffered'] != $stats['rows_fetched_from_client_ps_buffered'] ) 50 printf("[005] Buffered rows should be %d got %d.\n", 51 $stats['rows_fetched_from_client_ps_buffered'], 52 $after['rows_fetched_from_client_ps_buffered']); 53 54 $stats = $after; 55 printf("BUFFERED: rows_fetched_from_client_ps_unbuffered = %d\n", $stats['rows_fetched_from_client_ps_unbuffered']); 56 printf("BUFFERED: rows_fetched_from_client_ps_buffered = %d\n", $stats['rows_fetched_from_client_ps_buffered']); 57 printf("BUFFERED: rows_fetched_from_client_ps_cursor = %d\n", $stats['rows_fetched_from_client_ps_cursor']); 58 59 $id = null; 60 if (!mysqli_stmt_prepare($stmt, 'SELECT id FROM test') || 61 !mysqli_stmt_execute($stmt) || 62 !mysqli_stmt_bind_result($stmt, $id)) 63 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 64 65 $num_rows = 0; 66 while (mysqli_stmt_fetch($stmt)) 67 $num_rows++; 68 69 $after = mysqli_get_client_stats(); 70 $stats['rows_fetched_from_client_ps_unbuffered'] += $num_rows; 71 if ($after['rows_fetched_from_client_ps_unbuffered'] != $stats['rows_fetched_from_client_ps_unbuffered']) 72 printf("[007] Unbuffered rows should be %d got %d.\n", 73 $stats['rows_fetched_from_client_ps_unbuffered'], 74 $after['rows_fetched_from_client_ps_unbuffered']); 75 76 if ($after['rows_fetched_from_client_ps_buffered'] != $stats['rows_fetched_from_client_ps_buffered'] ) 77 printf("[005] Buffered rows should be unchanged, expecting %d got %d.\n", 78 $stats['rows_fetched_from_client_ps_buffered'], 79 $after['rows_fetched_from_client_ps_buffered']); 80 81 mysqli_stmt_free_result($stmt); 82 mysqli_stmt_close($stmt); 83 84 $stats = $after; 85 printf("UNBUFFERED: rows_fetched_from_client_ps_unbuffered = %d\n", $stats['rows_fetched_from_client_ps_unbuffered']); 86 printf("UNBUFFERED: rows_fetched_from_client_ps_buffered = %d\n", $stats['rows_fetched_from_client_ps_buffered']); 87 printf("UNBUFFERED: rows_fetched_from_client_ps_cursor = %d\n", $stats['rows_fetched_from_client_ps_cursor']); 88 89 mysqli_close($link); 90 print "done!"; 91?> 92--CLEAN-- 93<?php 94 require_once 'clean_table.inc'; 95?> 96--EXPECTF-- 97BEGINNING: rows_fetched_from_client_ps_unbuffered = %d 98BEGINNING: rows_fetched_from_client_ps_buffered = %d 99BEGINNING: rows_fetched_from_client_ps_cursor = 0 100BUFFERED: rows_fetched_from_client_ps_unbuffered = %d 101BUFFERED: rows_fetched_from_client_ps_buffered = %d 102BUFFERED: rows_fetched_from_client_ps_cursor = 0 103UNBUFFERED: rows_fetched_from_client_ps_unbuffered = %d 104UNBUFFERED: rows_fetched_from_client_ps_buffered = %d 105UNBUFFERED: rows_fetched_from_client_ps_cursor = 0 106done! 107