为什么网站最近经常出现“链接过多”的问题,刷新一下就好了。页面的,mysql_query()太多是不是就会引起这样的问题呢?怎么回事啊

解决方案 »

  1.   

    估计你同时有多个页面被刷新,这样每个HTTP请求都会产生一个连接请求。
    而MYSQL中对最大连接数是有限制的。你可以修改max_connections 参数以加大并发连接数。但最好先找到原因,为什么这么多连接请求,是不是在使用完后没有及时释放连接?
      

  2.   

    我每次查询玩了之后,都用mysql_free_result()函数了的以前我用VPS的时候就没有这个问题,前两天换了国内的空间,就这样的,怎么才能知道服务器设置的最大连接数呢
      

  3.   

    这个是我的数据库连接类
    <?
    #############
    #数据库链接类#
    #############class data_class{

    private $data_name;
    private $user_name;
    private $user_pass;
    private $data_address;
    private $conn;function __get($property_name){
    if(isset($this->$property_name)){
    return ($this->$property_name);
    }else{
    return (NULL);
    }
    }function __set($property_name,$value){
    $this->$property_name=$value;
    }function __construct($ip,$data,$user,$pass){
    $this->data_address=$ip;
    $this->data_name=$data;
    $this->user_name=$user;
    $this->user_pass=$pass;
    $this->conn=mysql_connect($this->data_address,$this->user_name,$this->user_pass) or die("

    <?xml version=\"1.0\" encoding=\"utf-8\"?>\n
    <!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n
    <html xmlns=\"http://www.w3.org/1999/xhtml\">\n
    <head>\n
    <meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\"/>\n
    <meta http-equiv=\"Cache-Control\" content=\"ust-revalidate\" forua=\"true\"/>\n
    <meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/>\n
        <meta http-equiv=\"Cache-Control\" content=\"max-age=0\" forua=\"true\"/>\n
        <meta http-equiv=\"Expires\" content=\"0\" forua=\"true\"/>\n
        <meta http-equiv=\"Pragma\" content=\"no-cache\" forua=\"true\"/>\n
    <link rel=\"shortcut icon\" href=\"/favicon.ico\" />\n
    <title>网站维护中</title>
    </head>
        <body>
    网站正在升级.....请稍后访问……<br/>
    <body>
    </html>
    ");
    mysql_query("set names 'utf8'",$this->conn);
    mysql_select_db("$this->data_name",$this->conn);

    }
    function __destruct(){
    mysql_close($this->conn);

    }}
    ?>
      

  4.   

    show variables like 'max%'
      

  5.   

    你通过phpadmin能连吗?或者通过php发一个查询过去,看看能不能弄到结果
      

  6.   


    mysql_free_result 只是释放结果集,并不是关闭连接。
    mysql> select @@max_connections;
    +-------------------+
    | @@max_connections |
    +-------------------+
    |               151 |
    +-------------------+
    1 row in set (0.00 sec)
      

  7.   


    mysql> select @@max_connections;
    +-------------------+
    | @@max_connections |
    +-------------------+
    |               151 |
    +-------------------+
    1 row in set (0.00 sec)这个能运行的哦