-->

2013-07-27

memo: mysql-proxy: proxy-lua-script

設定ファイル修正。
$ /usr/bin/sudo /usr/bin/rcsdiff /etc/config-archive/etc/mysql/mysql-proxy.cnf,v /etc/mysql/mysql-proxy.cnf
===================================================================
RCS file: /etc/config-archive/etc/mysql/mysql-proxy.cnf,v
retrieving revision 1.1
diff -r1.1 /etc/mysql/mysql-proxy.cnf
8c8
< #event-threads = ...
---
> event-threads = 3
16c16
< #max-open-files = ...
---
> max-open-files = 8192
33c33
< proxy-backend-addresses = 127.0.0.1:3306
---
> proxy-backend-addresses = 192.168.0.110:3306
35c35
< #proxy-lua-script = ...
---
> proxy-lua-script = /tmp/tutorial-keepalive.lua

lua-scriptファイル修正。
$ qlist mysql-proxy|grep -i tutorial-keepalive
/usr/share/doc/mysql-proxy-0.8.2/examples/tutorial-keepalive.lua.bz2
$ diff tutorial-keepalive.lua.orig tutorial-keepalive.lua
37,38c37,38
< local min_idle_connections = 4
< local max_idle_connections = 8
---
> local min_idle_connections = 40
> local max_idle_connections = 80

mysql, apache再起動。
sudo /etc/init.d/mysql-proxy stop && sudo /etc/init.d/mysql restart && sudo /etc/init.d/apache2 restart

手動で起動。ログを見る場合。
$ sudo /usr/bin/mysql-proxy --defaults-file=/etc/mysql/mysql-proxy.cnf

abコマンド。
(for CNT in $(seq 1 3); do for PERSISTENT in 0 1; do for DSN in 1 2; do for C in 5000; do \
N=`expr ${C} \* 5` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
mysqladmin status && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
ps aux|grep -iP "^apache\s" | wc -l && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && \
sleep 60 && echo "### END"; \
done; done; done; done;)

4パターン。pconnect有り無し×(mysqlTCP接続 or mysql-proxy経由)×3回。
同時接続数が多すぎて mysqlTCP接続+pconnect < mysqlTCP接続+connect になった。
pconnect無し+mysql-proxy経由が目的で80の持続的接続になった。
$ (for CNT in $(seq 1 3); do for PERSISTENT in 0 1; do for DSN in 1 2; do for C in 5000; do \
> N=`expr ${C} \* 5` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && \
sleep 60 && echo "### END"; \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> mysqladmin status && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> ps aux|grep -iP "^apache\s" | wc -l && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && \
> sleep 60 && echo "### END"; \
> done; done; done; done;)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
Complete requests:      25000
Requests per second:    2660.93 [#/sec] (mean)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
25071 200

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
Uptime: 32  Threads: 2  Questions: 100286  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3133.937

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
153

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
Complete requests:      25000
Requests per second:    683.66 [#/sec] (mean)

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
25000 200

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
Uptime: 129  Threads: 79  Questions: 275213  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 2133.434

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
251

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       77 |
+----------+
### END

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
Complete requests:      25000
Requests per second:    1055.95 [#/sec] (mean)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
25029 200

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
Uptime: 213  Threads: 252  Questions: 325275  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1527.112

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
251

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      250 |
+----------+
### END

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
Complete requests:      25000
Requests per second:    808.57 [#/sec] (mean)

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
24934 200
66 505

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
Uptime: 305  Threads: 206  Questions: 449742  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1474.563

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
251

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      204 |
+----------+
### END

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
Complete requests:      25000
Requests per second:    2500.22 [#/sec] (mean)

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
25122 200

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
Uptime: 375  Threads: 2  Questions: 550234  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1467.290

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
251

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
Complete requests:      25000
Requests per second:    542.38 [#/sec] (mean)

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
25000 200

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
Uptime: 482  Threads: 82  Questions: 725122  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1504.402

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
251

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       80 |
+----------+
### END

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
Complete requests:      25000
Requests per second:    1048.18 [#/sec] (mean)

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
25113 200

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
Uptime: 566  Threads: 252  Questions: 775360  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1369.893

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
251

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      250 |
+----------+
### END

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
Complete requests:      25000
Requests per second:    806.09 [#/sec] (mean)

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
24760 200
241 505

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
Uptime: 657  Threads: 207  Questions: 898991  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1368.327

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
251

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      205 |
+----------+
### END

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
Complete requests:      25000
Requests per second:    2492.24 [#/sec] (mean)

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
25009 200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
Uptime: 728  Threads: 2  Questions: 999031  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1372.295

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
250

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
Complete requests:      25000
Requests per second:    573.13 [#/sec] (mean)

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
25000 200

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
Uptime: 832  Threads: 74  Questions: 1174607  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1411.787

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
248

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       72 |
+----------+
### END

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
Complete requests:      25000
Requests per second:    1049.59 [#/sec] (mean)

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
25075 200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
Uptime: 916  Threads: 236  Questions: 1224876  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1337.200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
241

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      234 |
+----------+
### END

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
Complete requests:      25000
Requests per second:    792.33 [#/sec] (mean)

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
24860 200
140 505

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
Uptime: 1008  Threads: 215  Questions: 1349025  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1338.318

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
249

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      213 |
+----------+
### END

pconnectは同時接続数の見積もりがうまくいくと性能を発揮する。
$ (for CNT in $(seq 1 2); do for PERSISTENT in 0 1; do for DSN in 1; do for C in 250; do N=`expr ${C} \* 20` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && mysqladmin status && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && ps aux|grep -iP "^apache\s" | wc -l && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && sleep 0 && echo "### END"; done; done; done; done;)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
Complete requests:      5000
Requests per second:    3311.34 [#/sec] (mean)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
   5000 200

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
Uptime: 8  Threads: 1  Questions: 20001  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 2500.125

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
9

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
Complete requests:      5000
Requests per second:    4135.26 [#/sec] (mean)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
   5000 200

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
Uptime: 10  Threads: 7  Questions: 30011  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3001.100

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
7

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|        6 |
+----------+
### END

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
Complete requests:      5000
Requests per second:    1737.66 [#/sec] (mean)

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
   5000 200

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
Uptime: 13  Threads: 1  Questions: 50021  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3847.769

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
7

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
Complete requests:      5000
Requests per second:    3733.68 [#/sec] (mean)

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
   5001 200

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
Uptime: 15  Threads: 13  Questions: 60029  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 4001.933

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
13

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|       12 |
+----------+
### END

abコマンドに設定したスクリプト。
$ cat ab.php | perl -pe 's/([<>&])/{"<","<",">",">","&","&"}->{$1}/ge'
<?php
error_reporting(E_ALL|E_STRICT);
set_time_limit(0);

MAIN();
exit;

function MAIN()
{
    $dsn = isset($_GET["dsn"]) ? (int)$_GET["dsn"] : 1;
    $persistent = isset($_GET["persistent"]) ? (bool)$_GET["persistent"] : false;

    $server = "";
    $username = "";
    $password = "";
    switch ($dsn)
    {
    case 2:
        $server = "127.0.0.1:4040";
        $username = "test";
        $password = "test";
        break;
    case 1:
    default:
        $server = "192.168.0.110:3306";
        $username = "test";
        $password = "test";
        break;
    }

    $mysqlConnectFunc = $persistent ? "mysql_pconnect" : "mysql_connect";
    $link = $mysqlConnectFunc($server, $username, $password);
    if (!is_resource($link))
    {
        header('HTTP', true, 504);
        trigger_error(sprintf("mysql_pconnect error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }

    $result = mysql_query("SHOW FULL PROCESSLIST;", $link);
    if (!is_resource($result))
    {
        header('HTTP', true, 505);
        var_dump($result);
        trigger_error(sprintf("mysql_query error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }
    $num = mysql_num_rows($result);

    print "\$server: " . htmlspecialchars($server) . "<br />\n";
    print "\$username: " . htmlspecialchars($username) . "<br />\n";
    print "\$password: " . htmlspecialchars($password) . "<br />\n";

    print "number of lines: " . htmlspecialchars($num) . "<br />\n";
    print "<table border=1 style=\"empty-cells: show;\">\n";

    $cnt = 0;
    while ($row = mysql_fetch_assoc($result))
    {
        $cnt++;
        if ($cnt == 1)
        {
            print "<tr>\n";
            foreach ($row as $key => $val)
            {
                print "<th>" . htmlspecialchars($key) . "</th>\n";
            }
            print "</tr>\n";
        }

        print "<tr>\n";
        foreach ($row as $key => $val)
        {
            print "<td>" . htmlspecialchars($val) . "</td>\n";
        }
        print "</tr>\n";
    }
    print "</table>\n";

    mysql_free_result($result);

    $result = mysql_query("SET wait_timeout=30;");
    if (!is_resource($result) && $result != true)
    {
        header('HTTP', true, 505);
        var_dump($result);
        trigger_error(sprintf("mysql_query error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }
}

0 件のコメント: