1--TEST-- 2Killing a persistent connection. 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7require_once("connect.inc"); 8?> 9--INI-- 10mysqli.allow_persistent=1 11mysqli.max_persistent=2 12--FILE-- 13<?php 14 require_once("connect.inc"); 15 require_once("table.inc"); 16 17 $host = 'p:' . $host; 18 if (!$plink = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 19 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 20 $host, $user, $db, $port, $socket); 21 22 // get the thread ids of the two connections... 23 $thread_id = mysqli_thread_id($link); 24 $pthread_id = mysqli_thread_id($plink); 25 26 if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST')) 27 printf("[002] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 28 29 $running_threads = array(); 30 while ($row = mysqli_fetch_assoc($res)) 31 $running_threads[$row['Id']] = $row; 32 mysqli_free_result($res); 33 34 if (count($running_threads) < 2) 35 printf("[003] Processlist is too short, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 36 37 if (!isset($running_threads[$thread_id])) 38 printf("[004] Cannot find thread id of the regular link, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 39 40 if (!isset($running_threads[$pthread_id])) 41 printf("[005] Cannot find thread id of the persistent link, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 42 43 // Kill the persistent connection - don't use mysqli_kill, mysqlnd will catch that... 44 if (!mysqli_query($link, sprintf('KILL %d', $pthread_id))) 45 printf("[006] Cannot kill persistent connection, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 46 mysqli_close($plink); 47 // Give the server think-time to kill the pthread 48 sleep(1); 49 50 if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST')) 51 printf("[007] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 52 53 $running_threads2 = array(); 54 while ($row = mysqli_fetch_assoc($res)) 55 $running_threads2[$row['Id']] = $row; 56 mysqli_free_result($res); 57 58 if (isset($running_threads2[$pthread_id])) 59 printf("[008] Thread of the persistent connection should have been gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 60 if (!isset($running_threads2[$thread_id])) 61 printf("[009] Thread of the regular connection should be still there, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 62 63 // On PHP side this should do nothing. PHP should not try to close the connection or something. 64 try { 65 mysqli_close($plink); 66 } catch (Error $exception) { 67 echo $exception->getMessage() . "\n"; 68 } 69 70 if (!$plink = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 71 printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 72 $host, $user, $db, $port, $socket); 73 if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) { 74 printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink)); 75 } 76 77 @mysqli_free_result($res3); 78 @mysqli_close($plink); 79 mysqli_close($link); 80 81 // remove the "p:<host>" from the host variable 82 $host = substr($host, 2); 83 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 84 printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 85 $host, $user, $db, $port, $socket); 86 if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1')) 87 printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 88 89 mysqli_free_result($res4); 90 mysqli_close($link); 91 print "done!"; 92?> 93--CLEAN-- 94<?php 95 require_once("clean_table.inc"); 96?> 97--EXPECT-- 98mysqli object is already closed 99done! 100