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