|
![](/images/resource/spacer.gif) |
|
ช่วยด้วยค่ะ เรื่อง mysql connect timeout ใช้เวลานานไป |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ช่วยด้วยค่ะ เรื่อง mysql connect timeout
เพราะอยากจะเช็ค แค่ว่า mysql connect ok รึเปล่า ถ้าไม่สามารถเชื่อมต่อได้ ให้ใช้เวลาน้อยๆ กว่า 20+ s. อะค่ะ
เราสามารถตั้ง timeout mysql_connect นี้ได้ไหมค่ะ.. รบกวนหน่อยนะค่ะ
![timeout timeout](https://www.thaicreate.com/upload/stock/20150919123517.png?v=1001)
Code (PHP)
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
/*set_time_limit(3);
ini_set("connect_timeout","2");
ini_set('mysql.connect_timeout',"2");
ini_set('net_write_timeout',"2");
*/
include 'inc01.php';
$pass = new dbcon();
$COMPLEX_Ping = mysql_connect($pass->host_complex,$pass->user_complex,$pass->pwd_complex);
if(mysql_ping($COMPLEX_Ping)){
$BDR_Connect = mysql_connect($pass->host_bdr,$pass->user_bdr,$pass->pwd_bdr) or die ("Could not connect to MySQL at $pass->host_bdr ");
mysql_query("SET NAMES UTF8");
mysql_select_db($pass->db_sharp_member) or die ("Could not select $pass->db_sharp_member database");
$strSQL = "UPDATE chack_connect SET Connect = 'Yes' WHERE Pian = 'complex'";
$objQuery = mysql_query($strSQL);
mysql_close($BDR_Connect);
echo 'Complex Connect OK <br />';
} else {
$BDR_Connect = mysql_connect($pass->host_bdr,$pass->user_bdr,$pass->pwd_bdr) or die ("Could not connect to MySQL at $pass->host_bdr ");
mysql_query("SET NAMES UTF8");
mysql_select_db($pass->db_sharp_member) or die ("Could not select $pass->db_sharp_member database");
$strSQL = "UPDATE chack_connect SET Connect = 'No' WHERE Pian = 'complex'";
$objQuery = mysql_query($strSQL);
mysql_close($BDR_Connect);
echo 'Complex Connect Fall <br />';
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round(($endtime - $starttime),3);
echo "time : ".$totaltime." sec.";
?>
Tag : PHP, MySQL, CakePHP
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-09-19 12:44:57 |
By :
Jirata |
View :
2218 |
Reply :
1 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ไม่เคย set ด้วย php นะครับ รู้แต่ว่าเซทที่ mysql server
น่าจะเซทที่ my.cnf แต่จำคำสั่งไม่ได้
ปล. แล้วก็ไม่นิยมทำ คือเมื่อมัน connect ไม่ได้ก็จบโปรแกรมไป จะช้า ก็ไม่นานมั้งครับ
|
ประวัติการแก้ไข 2015-09-19 18:29:40
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-09-19 18:28:33 |
By :
NewbiePHP |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|