Script berikut ini berfungsi menghitung jumlah koneksi aktif di database mysql. SCript ini bisa anda gunakan untuk monitoring query yang mungkin looping sehingga mengakibatkan koneksi database terputus.
Berikut ini scriptnya
<?php define('DB_HOST','mysql_host'); define('DB_USER','mysql_user'); define('DB_PASSWORD','mysql_passwd'); $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect: ' . mysql_error()); echo "TOTAL Koneksi<br>"; $rs = mysql_query("SELECT host,count(host) FROM information_schema.processlist GROUP BY host"); $data = mysql_fetch_assoc($rs); echo "<pre>"; print_r($data); echo "</pre>"; echo "Total Thread<br>"; $rs = mysql_query("SELECT variable_value FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE variable_name='threads_connected'"); $data = mysql_fetch_assoc($rs); echo "<pre>"; print_r($data); echo "</pre>"; echo "Listing Proses<br>"; $processlist=array(); $rs = mysql_query("SELECT host,command,info FROM information_schema.processlist"); while($row=mysql_fetch_assoc($rs)){ $processlist[] = $row['host'].' '.$row['command'].' '.$row['info']; } echo "<pre>"; print_r($processlist); echo "</pre>"; ?>
Selamat mencoba