サンプル集 |
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■other |
Linuxコマンド |
用語集 |
debian メモ |
apache2 メモ |
MySQL メモ |
Oracle メモ |
HOME |
phpからmysqlへ接続した後、コネクションを放っておいたら、ちゃんと解放されるでしょうか。
◆環境OS | Windows XP Professional Version 2002 Service Pack 2 |
---|---|
PHP | 5.2.4 |
MySQL | 5.0.27 |
MySQLの現在コネクション数はshow statusで確認できます。
> mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24 to server version: 5.0.27-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show status;
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
:
| Threads_connected | 1 |
:
+-----------------------------------+----------+
245 rows in set (0.00 sec)
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24 to server version: 5.0.27-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show status;
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
:
| Threads_connected | 1 |
:
+-----------------------------------+----------+
245 rows in set (0.00 sec)
Threads_connectedが接続数を表しています。 現在は1です。 この1はおそらく自分自身でしょう。 試しにもう1つDOS窓を開けてつないでみます。
mysql> show status;
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
:
| Threads_connected | 2 |
:
+-----------------------------------+----------+
245 rows in set (0.00 sec)
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
:
| Threads_connected | 2 |
:
+-----------------------------------+----------+
245 rows in set (0.00 sec)
2になりました。
phpからつないでみます。
php013.php | ||
|
実行してみます。
> php php013.php
接続成功!!
接続成功!!
接続成功したらThreads_connectedが2になり、phpが終了したら1になったので、何もしなくても解放されている模様です。
2009/05/19 追記
show status を実行すると全部の項目が出てしまいます。 like 指定で、絞り込むことができます。
mysql> show status like 'Threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 17 |
+-------------------+-------+
1 row in set (0.09 sec)
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 17 |
+-------------------+-------+
1 row in set (0.09 sec)
% で部分一致検索もできます。
mysql> show status like 'Threads_%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 0 |
| Threads_connected | 17 |
| Threads_created | 41120 |
| Threads_running | 2 |
+-------------------+-------+
4 rows in set (0.11 sec)
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 0 |
| Threads_connected | 17 |
| Threads_created | 41120 |
| Threads_running | 2 |
+-------------------+-------+
4 rows in set (0.11 sec)
便利ですね。
Copyright (C) 2012 ymlib.com