TP简单查询语句很快内存耗尽

浏览:5481 发布日期:2013/06/02 分类:求助交流 关键字: apache,内存
访问这个方法:    public function test(){
        $m=M('tag');
        $q=$this->_get("q");
        if ($q){
            $tag=$m->where("status=1 and name like '%".$q."%'")->field('tagId as id,name')->order('count')->limit(20)->select();
        }
        else{
            $tag=$m->where("status=1")->field('tagId as id,name')->order('count')->limit(20)->select();
        }
        $this->ajaxReturn($tag,'JSON');
    }
描述:方位其他应用时很正常,访问这个方法时连续访问几次,内存就会很快增加,一个请求需要几分钟才能返回数据。甚至因为内存耗尽而崩溃。
错误提示:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 16384 bytes)
php.ini设置是这样的max_execution_time = 30
max_input_time = 60
memory_limit = 360M
apache采用的是prework模式,设置如下:Timeout 60
KeepAlive On
MaxKeepAliveRequests 10
KeepAliveTimeout 5
## Server-Pool Size Regulation (MPM specific)

<IfModule mpm_prefork_module>
     StartServers          5
     MinSpareServers       5
     MaxSpareServers      10
     MaxClients           100
     MaxRequestsPerChild  500
</IfModule>
tag表里只有是6条记录和3000条记录时,问题是一样的。执行的查询语句在mysql下执行时,经过多次实验时间可以忽略不计。
此后我将php.ini的内存限制设置成了300M,但是还是很快崩溃。


使用原生态的php进行操作就没有问题:        $q=$this->_get("q");
        $tag=array();
        mysql_connect('localhost:3306', huiyi', '*****')
            or die("Could not connect: " . mysql_error());
        mysql_select_db("huiyi");
        $result = mysql_query("select tagId as id,name from hy_tag where status=1 and name like '%".$q."%' limit 20")
            or die("Query failed: " . mysql_error());
        $i = 0;
        while ($row = mysql_fetch_assoc($result)) {            
            array_push($tag, $row);        
        }
        $this->ajaxReturn($tag,'JSON');

附件 1.png ( 89.61 KB 下载:10 次 )

最佳答案
评论( 相关
后面还有条评论,点击查看>>