您好,登錄后才能下訂單哦!
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 41007872 bytes)
很明顯是內(nèi)存溢出。
1.直接修改PHP.INI
memory_limit = xxxx M ;
2.修改.htaccess
php_value memory_limit xxx M
3.直接在程序頁面上修改。
ini_set(‘memory_limit’, ‘xxx M);
上述方案都是通過調(diào)整內(nèi)存大小限制,沒法解決根本問題。達(dá)到更高一量級的數(shù)據(jù),內(nèi)存肯定不夠用。
請看代碼:
$list = function () use ($result, $areaList, $industryList, $channelList, $useStatusList, $billServiceFollow, $serviceOrderAmount, $statistics, $adminUserInfo, $implementerInfo, $salesInfo) {
foreach ($result as $value) {
$value['province_name'] = $areaList[$value['province_id']] ?? '無';//省份
$value['city_name'] = $areaList[$value['city_id']] ?? '無';//城市
$industry = $value['industry'] ?? 0;
$value['industry_name'] = $industryList[$industry] ?? '無';//行業(yè)
$channel = $value['channel'] ?? 0;
$value['channel_name'] = $channelList[$channel] ?? '無';//客戶來源
$useStatus = $value['use_status'];
$value['contract_type'] = $useStatusList[$useStatus] ?? '';//合同類型
if ($useStatus == 1) {//正式合同
$startTime = $value['formal_starttime'] ?? 0;
if ($startTime == '0000-00-00 00:00:00') {
$startTime = 0;
}
$endTime = $value['formal_endtime'] ?? 0;
if ($startTime == '0000-00-00 00:00:00') {
$endTime = 0;
}
$value['contract_begin_date'] = !empty($startTime) ? date('Y-m-d', strtotime($startTime)) : '無';
$value['contract_end_date'] = !empty($endTime) ? date('Y-m-d', strtotime($endTime)) : '無';
} else {//試用合同
$startTime = $value['tryout_starttime'] ?? 0;
if ($startTime == '0000-00-00 00:00:00') {
$startTime = 0;
}
$endTime = $value['tryout_endtime'] ?? 0;
if ($startTime == '0000-00-00 00:00:00') {
$endTime = 0;
}
$value['contract_begin_date'] = !empty($startTime) ? date('Y-m-d', strtotime($startTime)) : '無';
$value['contract_end_date'] = !empty($endTime) ? date('Y-m-d', strtotime($endTime)) : '無';
}
$value['acenum'] = $statistics[$value['id']]['acenum'] ?? 0;//賬套數(shù)量
$value['usernum'] = $statistics[$value['id']]['usernum'] ?? 0;//會計(jì)數(shù)量
$value['vounum'] = $statistics[$value['id']]['vounum'] ?? 0;//憑證
$value['billnum'] = $statistics[$value['id']]['billnum'] ?? 0;//上傳票據(jù)
//購買票據(jù)數(shù)量
$totalServiceNum = $billServiceFollow[$value['id']]['total_service_num'] ?? 0;
if ($totalServiceNum >= 100000000) {
$totalServiceNum = '不限量';
}
$value['total_service_num'] = $totalServiceNum;
//成交金額
$value['total_recive_amount'] = $serviceOrderAmount[$value['id']]['total_recive_amount'] ?? 0;
$value['create_by_name'] = $adminUserInfo[$value['create_by']] ?? '無';
//實(shí)施名稱
$implementer = $value['implement'] ?? 0;
$value['implementer'] = $implementerInfo[$implementer] ?? '無';
//銷售
$sale = $value['sale_id'] ?? 0;
$value['sale'] = $salesInfo[$sale] ?? '無';
$abutment = $value['abutment'] ?? 0;
$value['abutment'] = $salesInfo[$abutment] ?? '無';
yield $value;
}
};
$data['list'] = $list();
//調(diào)用下載excel
$excel = new DownloadExcel();
return $excel->title('客戶列表')->subtitle('')->subject('')->fill('company-list', $data)->download();
內(nèi)存溢出
1.將大結(jié)果集的數(shù)據(jù)單元yield,傳給生成器。
2.通過function()use{};匿名函數(shù)接收生成器作為結(jié)果。$data['list'] = $list();
后續(xù)只需要迭代$data['list']即可。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。