php - phalcon 查询 内存耗尽问题
ringa_lee
ringa_lee 2017-06-28 09:22:58
0
1
765

使用phalcon框架,进行如下查询

public function getCarSeriesList($brandId, $start = 0, $count = 1000){

    $phql = "SELECT cs.*, b.* FROM Test\Common\Models\Entities\CarSeries cs LEFT JOIN Test\Common\Models\Entities\CarBrands b ON cs.brandId = b.id ";
    $condition = array();
    if(!empty($brandId)){

        $phql .= " WHERE cs.brandId = ?0 ";
        $condition[0] = $brandId;
    }
    $phql .= " ORDER BY cs.name_en ASC ";
    if(!empty($count)){

        $phql .= " LIMIT ?1, ?2";
        $condition[1] = $start;
        $condition[2] = $count;
    }

    $result = $this->modelsManager->executeQuery($phql, $condition);

    return $result->toArray();
}

结果php-fpm 进程报错:

2017/06/27 17:07:49 [error] 60709#0: *1028 FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 532692992 bytes) in /Users/tester/www/testserver/apps/backend/controllers/CarSeriesController.php on line 27" while reading response header from upstream, client: 127.0.0.1, server: local.test.me, request: "GET /series HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "admin.local.test.me"

已将php.ini的memory_limit的值,从128M修改为512M,依然会有这个问题。请问各位是否遇到过类似问题?

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
阿神

1、这个不是phalcon的问题 是php的问题
2、查询的数据太大了,把它全加载到内存里肯定会报这个
3、可以通过ini_set("memory_limit","-1");来解决,但是。。。。作为一个线上项目绝逼不建议这样做
4、一次性查出的数据量太大,你需要优化你的程序,而不是通过修改某些系统参数,

(1)你可以检查下你的代码,因为你是cs.*,b.* 你看下是不是所有的字段都是必要的,不必要的字段就不要查    出来,只取有用的字段.
(2)你的查询条件太少,如果本来就这样的话,那你可以通过分段去获取,你这样查,并且还是联表查,这么大的数据量,对于mysql都是负担,如果多个请求进来,分分钟挂了
(3)优化你的数据表结构
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!