PHP  
 PHP_HEAD
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/mysqli/tests/mysqli_pconn_max_links.phpt ('Persistent connections and mysqli.max_links')

Script

1: <?php
2:     
require_once("connect.inc");
3:     require_once(
'table.inc');
4:
5:
6:     if (!
mysqli_query($link'DROP USER pcontest') ||
7:         !
mysqli_query($link'DROP USER pcontest@localhost') ||
8:         !
mysqli_query($link'CREATE USER pcontest@"%" IDENTIFIED BY "pcontest"') ||
9:         !
mysqli_query($link'CREATE USER pcontest@localhost IDENTIFIED BY "pcontest"') ||
10:         !
mysqli_query($linksprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'"$db)) ||
11:         !
mysqli_query($linksprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'localhost'"$db))) {
12:         
printf("[000] Init failed, [%d] %s\n",
13:             
mysqli_errno($plink), mysqli_error($plink));
14:     }
15:
16:     
var_dump(mysqli_get_links_stats(1));
17:
18:     echo 
"Before pconnect:";
19:     
var_dump(mysqli_get_links_stats());
20:
21:     if (!
$plink my_mysqli_connect('p:' $host'pcontest''pcontest'$db$port$socket))
22:         
printf("[001] Cannot connect using the second DB user created during SKIPIF, [%d] %s\n",
23:             
mysqli_connect_errno(), mysqli_connect_error());
24:
25:     echo 
"After pconnect:";
26:     
var_dump(mysqli_get_links_stats());
27:
28:     
ob_start();
29:     
phpinfo();
30:     
$phpinfo strip_tags(ob_get_contents());
31:     
ob_end_clean();
32:
33:     
$phpinfo substr($phpinfostrpos($phpinfo'MysqlI Support => enabled'), 500);
34:     if (!
preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU'$phpinfo$matches))
35:         
printf("[002] Cannot get # active persistent links from phpinfo()\n");
36:     
$num_plinks $matches[1];
37:
38:     if (!
$res mysqli_query($plink'SELECT id, label FROM test WHERE id = 1'))
39:         
printf("[003] Cannot run query on persistent connection of second DB user, [%d] %s\n",
40:             
mysqli_errno($plink), mysqli_error($plink));
41:
42:     if (!
$row mysqli_fetch_assoc($res))
43:         
printf("[004] Cannot run fetch result, [%d] %s\n",
44:             
mysqli_errno($plink), mysqli_error($plink));
45:     
mysqli_free_result($res);
46:     
var_dump($row);
47:
48:     
// change the password for the second DB user and kill the persistent connection
49:     
if (!mysqli_query($link'SET PASSWORD FOR pcontest = PASSWORD("newpass")') ||
50:             !
mysqli_query($link'FLUSH PRIVILEGES'))
51:         
printf("[005] Cannot change PW of second DB user, [%d] %s\n"mysqli_errno($link), mysqli_error($link));
52:
53:         
// change the password for the second DB user and kill the persistent connection
54:     
if (!mysqli_query($link'SET PASSWORD FOR pcontest@localhost = PASSWORD("newpass")') ||
55:             !
mysqli_query($link'FLUSH PRIVILEGES'))
56:         
printf("[006] Cannot change PW of second DB user, [%d] %s\n"mysqli_errno($link), mysqli_error($link));
57:
58:     
// persistent connections cannot be closed but only be killed
59:     
$pthread_id mysqli_thread_id($plink);
60:     if (!
mysqli_query($linksprintf('KILL %d'$pthread_id)))
61:         
printf("[007] Cannot KILL persistent connection of second DB user, [%d] %s\n"mysqli_errno($link), mysqli_error($link));
62:     
// give the server a second to really kill the thread
63:     
sleep(1);
64:
65:     if (!
$res mysqli_query($link"SHOW FULL PROCESSLIST"))
66:         
printf("[008] [%d] %s\n"mysqli_errno($link), mysqli_error($link));
67:
68:     
$running_threads = array();
69:     while (
$row mysqli_fetch_assoc($res))
70:         
$running_threads[$row['Id']] = $row;
71:     
mysqli_free_result($res);
72:
73:     if (isset(
$running_threads[$pthread_id]))
74:         
printf("[009] Persistent connection has not been killed\n");
75:
76:     echo 
"Before second pconnect:";
77:     
var_dump(mysqli_get_links_stats());
78:
79:     
// this fails and we have 0 (<= $num_plinks) connections
80:     
if ($plink = @my_mysqli_connect('p:' $host'pcontest''pcontest'$db$port$socket))
81:         
printf("[010] Can connect using the old password, [%d] %s\n",
82:             
mysqli_connect_errno($link), mysqli_connect_error($link));
83:
84:     echo 
"After second pconnect:";
85:     
var_dump(mysqli_get_links_stats());
86:
87:     
ob_start();
88:     
phpinfo();
89:     
$phpinfo strip_tags(ob_get_contents());
90:     
ob_end_clean();
91:     
$phpinfo substr($phpinfostripos($phpinfo'MysqlI Support => enabled'), 500);
92:     if (!
preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU'$phpinfo$matches))
93:         
printf("[010] Cannot get # of active persistent links from phpinfo()\n");
94:
95:     
var_dump(mysqli_get_links_stats());
96:
97:     
$num_plinks_kill $matches[1];
98:     
$sstats mysqli_get_links_stats();
99:     if (
$sstats['active_plinks'] != $num_plinks_kill) {
100:         
printf("[010.2] Num of active plinks differ %s %s\n"$sstats['active_plinks'], $num_plinks_kill);
101:     }
102:     if (
$num_plinks_kill $num_plinks)
103:         
printf("[011] Expecting Active Persistent Links < %d, got %d\n"$num_plinks$num_plinks_kill);
104:
105:     if (!
$plink my_mysqli_connect('p:' $host'pcontest''newpass'$db$port$socket))
106:         
printf("[012] Cannot connect using the new password, [%d] %s\n",
107:             
mysqli_connect_errno(), mysqli_connect_error());
108:
109:     if (!
$res mysqli_query($plink'SELECT id, label FROM test WHERE id = 1'))
110:         
printf("[013] Cannot run query on persistent connection of second DB user, [%d] %s\n",
111:             
mysqli_errno($plink), mysqli_error($plink));
112:
113:     if (!
$row mysqli_fetch_assoc($res))
114:         
printf("[014] Cannot run fetch result, [%d] %s\n",
115:             
mysqli_errno($plink), mysqli_error($plink));
116:     
mysqli_free_result($res);
117:     
var_dump($row);
118:
119:     if (
$plink2 my_mysqli_connect('p:' $host'pcontest''newpass'$db$port$socket)) {
120:         
printf("[015] Can open more persistent connections than allowed, [%d] %s\n",
121:             
mysqli_connect_errno(), mysqli_connect_error());
122:         
var_dump(mysqli_get_links_stats());
123:     }
124:
125:     
ob_start();
126:     
phpinfo();
127:     
$phpinfo strip_tags(ob_get_contents());
128:     
ob_end_clean();
129:     
$phpinfo substr($phpinfostripos($phpinfo'MysqlI Support => enabled'), 500);
130:     if (!
preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU'$phpinfo$matches))
131:         
printf("[016] Cannot get # of active persistent links from phpinfo()\n");
132:
133:     
$num_plinks $matches[1];
134:     if (
$num_plinks > (int)ini_get('mysqli.max_persistent'))
135:         
printf("[017] mysqli.max_persistent=%d allows %d open connections!\n"ini_get('mysqli.max_persistent'),$num_plinks);
136:
137:     
mysqli_query($link'REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest');
138:     
mysqli_query($link'DROP USER pcontest');
139:     
mysqli_close($link);
140:     print 
"done!";
141:
?>
142:

Expected

Warning: mysqli_get_links_stats(): no parameters expected in %s on line %d
NULL
Before pconnect:array(3) {
  ["total"]=>
  int(1)
  ["active_plinks"]=>
  int(0)
  ["cached_plinks"]=>
  int(0)
}
After pconnect:array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(0)
}
array(2) {
  ["id"]=>
  string(1) "1"
  ["label"]=>
  string(1) "a"
}
Before second pconnect:array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(0)
}

Warning: main(): MySQL server has gone away in %s on line %d

Warning: main(): Error reading result set's header in %s line %d
After second pconnect:array(3) {
  ["total"]=>
  int(1)
  ["active_plinks"]=>
  int(0)
  ["cached_plinks"]=>
  int(0)
}
array(3) {
  ["total"]=>
  int(1)
  ["active_plinks"]=>
  int(0)
  ["cached_plinks"]=>
  int(0)
}
array(2) {
  ["id"]=>
  string(1) "1"
  ["label"]=>
  string(1) "a"
}
[015] Can open more persistent connections than allowed, [0] 
array(3) {
  ["total"]=>
  int(3)
  ["active_plinks"]=>
  int(2)
  ["cached_plinks"]=>
  int(0)
}
done!

Output

Warning: mysqli_get_links_stats(): no parameters expected in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 16
NULL
Before pconnect:array(3) {
  ["total"]=>
  int(1)
  ["active_plinks"]=>
  int(0)
  ["cached_plinks"]=>
  int(0)
}
After pconnect:array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(0)
}
array(2) {
  ["id"]=>
  string(1) "1"
  ["label"]=>
  string(1) "a"
}
[005] Cannot change PW of second DB user, [1044] Access denied for user 'phpqa'@'localhost' to database 'mysql'
[006] Cannot change PW of second DB user, [1044] Access denied for user 'phpqa'@'localhost' to database 'mysql'
[007] Cannot KILL persistent connection of second DB user, [1095] You are not owner of thread 50374
Before second pconnect:array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(0)
}
[010] Can connect using the old password, [0] 
After second pconnect:array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(1)
}
array(3) {
  ["total"]=>
  int(2)
  ["active_plinks"]=>
  int(1)
  ["cached_plinks"]=>
  int(1)
}

Warning: mysqli_real_connect(): Too many open persistent links (2) in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/connect.inc on line 94
[012] Cannot connect using the new password, [0] 

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 109

Warning: mysqli_errno() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 111

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 111
[013] Cannot run query on persistent connection of second DB user, [0] 

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 113

Warning: mysqli_errno() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 115

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 115
[014] Cannot run fetch result, [0] 

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 116
NULL

Warning: mysqli_real_connect(): Too many open persistent links (2) in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/connect.inc on line 94
done!

Diff

025+ [005] Cannot change PW of second DB user, [1044] Access denied for user 'phpqa'@'localhost' to database 'mysql'
026+ [006] Cannot change PW of second DB user, [1044] Access denied for user 'phpqa'@'localhost' to database 'mysql'
027+ [007] Cannot KILL persistent connection of second DB user, [1095] You are not owner of thread 50374
033- 
034- Warning: main(): MySQL server has gone away in %s on line %d
035- 
036- Warning: main(): Error reading result set's header in %s line %d
036+ [010] Can connect using the old password, [0] 
039+   int(2)
040+   ["active_plinks"]=>
040-   ["active_plinks"]=>
041-   int(0)
042-   ["cached_plinks"]=>
043-   int(0)
042+   ["cached_plinks"]=>
043+   int(1)
047+   int(2)
048+   ["active_plinks"]=>
048-   ["active_plinks"]=>
049-   int(0)
050-   ["cached_plinks"]=>
051-   int(0)
050+   ["cached_plinks"]=>
051+   int(1)
053+ 
054+ Warning: mysqli_real_connect(): Too many open persistent links (2) in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/connect.inc on line 94
055+ [012] Cannot connect using the new password, [0] 
056+ 
057+ Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 109
058+ 
059+ Warning: mysqli_errno() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 111
060+ 
061+ Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 111
062+ [013] Cannot run query on persistent connection of second DB user, [0] 
063+ 
064+ Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 113
065+ 
066+ Warning: mysqli_errno() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 115
067+ 
068+ Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 115
069+ [014] Cannot run fetch result, [0] 
070+ 
071+ Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, null given in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/mysqli_pconn_max_links.php on line 116
072+ NULL
073+ 
074+ Warning: mysqli_real_connect(): Too many open persistent links (2) in /var/php_gcov/PHP_HEAD/ext/mysqli/tests/connect.inc on line 94
053- array(2) {
054-   ["id"]=>
055-   string(1) "1"
056-   ["label"]=>
057-   string(1) "a"
058- }
059- [015] Can open more persistent connections than allowed, [0] 
060- array(3) {
061-   ["total"]=>
062-   int(3)
063-   ["active_plinks"]=>
064-   int(2)
065-   ["cached_plinks"]=>
066-   int(0)
067- }

 

Generated at Mon, 04 Aug 2014 15:49:20 +0000 (25 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.