使用phalcon框架,進(jìn)行如下查詢
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();
}
結(jié)果php-fpm 進(jìn)程報(bào)錯(cuò):
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,依然會(huì)有這個(gè)問題。請(qǐng)問各位是否遇到過類似問題?
ringa_lee
1、這個(gè)不是phalcon的問題 是php的問題
2、查詢的數(shù)據(jù)太大了,把它全加載到內(nèi)存里肯定會(huì)報(bào)這個(gè)
3、可以通過ini_set("memory_limit","-1");來解決,但是。。。。作為一個(gè)線上項(xiàng)目絕逼不建議這樣做
4、一次性查出的數(shù)據(jù)量太大,你需要優(yōu)化你的程序,而不是通過修改某些系統(tǒng)參數(shù),
(1)你可以檢查下你的代碼,因?yàn)槟闶莄s.*,b.* 你看下是不是所有的字段都是必要的,不必要的字段就不要查 出來,只取有用的字段.
(2)你的查詢條件太少,如果本來就這樣的話,那你可以通過分段去獲取,你這樣查,并且還是聯(lián)表查,這么大的數(shù)據(jù)量,對(duì)于mysql都是負(fù)擔(dān),如果多個(gè)請(qǐng)求進(jìn)來,分分鐘掛了
(3)優(yōu)化你的數(shù)據(jù)表結(jié)構(gòu)