php - phalcon 查詢 記憶體耗盡問題
ringa_lee
ringa_lee 2017-06-28 09:22:58
0
1
695

使用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 trites to extedby /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學習者快速成長!