I'm twiting

访问统计

free counters

Zabbix的一个bug

最近公司的项目要分解zabbix。分析它的代码的时候发现其数据库类有一个bug:使用mysql_pconnect建立一个数据库连接,却用mysql_close去关闭!这样做是关不掉的!因为mysql_pconnect建立的是一个持久化的连接,使用完毕会被放回连接池的,即使脚本执行完毕,这个连接也不会关闭。

一下是php.net对mysql_close的解释:

mysql_close() closes the non-persistent connection to the MySQL server that’s associated with the specified link identifier. If link_identifier isn’t specified, the last opened link is used.

一下是有问题的代码片段:

$mysql_server = $DB['SERVER'].( !empty($DB['PORT']) ? ‘:’.$DB['PORT'] : ”);

if (!$DB['DB']= mysql_pconnect($mysql_server,$DB['USER'],$DB['PASSWORD'])){
$error = ‘Error connecting to database ['.mysql_error().']‘;
$result = false;
}
else{
if (!mysql_select_db($DB['DATABASE'])){
$error = ‘Error database selection ['.mysql_error().']‘;
$result = false;
}
}
break;

$result = mysql_close($DB['DB']);
break;

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>