dshdsh2016 2013-01-09 20:05
浏览 26

保持对mysql标识符的引用是否有问题?

My web server run into such errors :

Server: example.com User: yyy MySQL Connection Limit: Current MySQL Connections: 81

I am investigating on the reasons of this problem.

The PHP manual says :

Freeing resources

Thanks to the reference-counting system introduced with PHP 4's Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually.

So, does keeping a reference to a MySQL identifier could be a problem for website with pages displayed in more than 3 seconds (generally) ?

I manage MySQL connections like that :

1 - I keep a global variable $LINK as a reference to the MySQL resource

//MySQL connection
$LINK = 0;
function db_connect(){
    //get variables
    global $LINK,$CONF;

    if($LINK == 0){
        $LINK = @mysql_connect($CONF['host'], $CONF['user'], $CONF['password'])){
    }
}

2 - I use a function like this one to do queries :

function db_query($sql){
    global $LINK,$CONF,$NB_QUERIES,$TEMPS_QUERIES,$queries, $CLOSED;

    if(db_connect()){
        //do some debug stuff if needed

        //execute the query
        $result = @mysql_query($sql,$LINK);

        //do some other debug stuff if needed

        return $result;
    } else {
        return 0;
    }
}

Am I looking in the right direction or there are some others things to look at first when having such errors?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题