Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)
一段PHP程序执行报错:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)
去百度了一下,原来是php.ini中的内存分配的问题,默认php代码能够申请到的最大内存字节数就是134217728 bytes,如果代码执行的时候再需要更多的内存,就会报错了,于是就将php.ini文件中的配置改了一下:
代码如下:
但是之后一想,一个php脚本一次请求的内存空间就要超过128M,那不管你以后将memory_limit设置成多大,以后肯定有出问题的时候。
究其原因,是我在在编码时,仅仅对变量赋值,却从来没有 unset ($var) 过。导致了内存占用越来越多,所以以后一个变量不再使用之后,一定要记得unset掉它。
protected function execute(InputInterface $input, OutputInterface $output)
{
//ini_set('max_execution_time', '0');
$answerService = new AnswerService();
$taskService = new TaskService();
$taskStudentService = new TaskStudentService();
$statService = new StatService();
$stuService = new StudentService(); $unMarkedStudents = $taskService->findUnMarkedStudent();
if(count($unMarkedStudents)>0){
foreach($unMarkedStudents as $taskStuInfo) {
$unMarkedQuestions = $taskService->findUnMarkedQuestion($taskStuInfo['taskId'],$taskStuInfo['studentId']);
foreach($unMarkedQuestions as $v){
$answerService->submitUnmarks($taskStuInfo['id'],$taskStuInfo['taskId'],$taskStuInfo['studentId'],$v['questionId'],
$v['subIndexes']);
}
//修改taskStudent表的status状态
$taskStudentInfo = $taskStudentService->get($taskStuInfo['id']);
$taskStudentInfo->updateTime = new \DateTime();
$taskStudentInfo->status = 'MARKED';
$taskStudentService->update($taskStudentInfo,true); unset($taskStudentInfo);
//生成该学生的趋势
$stuInfo = $stuService->get($taskStuInfo['studentId']);
$statService->calTaskPolyFit($stuInfo, $taskStuInfo['subject']);
unset($stuInfo);
unset($unMarkedQuestions);
}
} else {
return false;
}
}
完毕。
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)的更多相关文章
- PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted 错误
php运行一段时间后,部分页面打不开,查看nginx日志里面一直在报PHP message: PHP Fatal error: Allowed memory size of 134217728 by ...
- Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes) in
最近莫名出现这个错误. 研究一下原因很奇葩呢. 原因:sql获取数据库中数据,取出数据赋给变量,数据太多,超过memory_limit内存设置了. 解决方法:设置memory_limit不建议.优化代 ...
- Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in
解释是可用内存已耗尽,这关系到PHP的memory_limit的设置问题. 我在网上看到,有两种方法解决 1.修改php.ini memory_limit = 128 这种方法需要重启服务器,很显然, ...
- Fatal error: Allowed memory size of 524288000 bytes exhausted (tried to allocate 64 bytes) in D
Fatal error: Allowed memory size of 524288000 bytes exhausted (tried to allocate 64 bytes) in D 从数据库 ...
- Fatal error: Allowed memory size of 8388608 bytes exhausted
这两天安装bugfree,更换了一个数据量较大的库,结果打开bug详情页要么是空白页,要么就报如题的错误,错误信息还包括C:\wamp\www\bugfree\Include\Class\ADOLit ...
- (转载)PHP的内存限制 Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in
(转载)http://blog.csdn.net/beyondlpf/article/details/7794028 Fatal error: Allowed memory size of 13421 ...
- Allowed memory size of 134217728 bytes exhausted解决办法(php内存耗尽报错)【简记】
报错: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) i ...
- php的Allowed memory size of 134217728 bytes exhausted问题解决办法
php的Allowed memory size of 134217728 bytes exhausted问题解决办法 报错: Fatal error: Allowed memory size of 1 ...
- PHP的内存限制 Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in Fa ...
随机推荐
- Flask刷新问题
修改页面中内容,特别是图片后,总是刷新不了.调试时,我常常通过修改端口来解决,从80-99不断改. 服务器部署,也遇到同样问题,重启web服务器,重启计算机都不行,网页已经改过来了,但是图片还是老图片 ...
- 基于VM10+Win7安装Mac OSX10.11 El Capitan
前言 此文写给那些像我一样的屌丝程序员(呵呵,我现在从事的是最底层的工作了,但是不想放弃我的梦想) 说明 基于VM10+Win7安装Mac OSX10.11 El Capitan 工具 VMware- ...
- windows下根据进程ID强制杀死进程
[windows 进程ID PID]NTSD命令详解 1. ntsd -c q -p PID 2. ntsd -c q -pn ImageName 比如:ntsd -c q -pn qq.exe -c ...
- requestFeature() must be called before adding content产生原因和解决办法
03-24 01:07:31.504 2957-2957/com.santai.jrj E/AndroidRuntime: FATAL EXCEPTION: main Process: com.san ...
- Core Java-多线程-线程的生命周期
0. 在介绍线程前我们先看一下什么是进程? 进程是线程的母亲,如果在大学计算机课程里读过操作系统一定不会陌生. 所谓进程,它是计算机程序关于某数据集上的一次活动,是系统进行资源分配和调度的基本单位,是 ...
- Apache和Nginx对比
面试过程中被问到Apache和Nginx服务器的对比,因为之前没有关注过这个问题,所以也没能回答上来. 今天在网上搜索资料,发现中文资料极少,还是英文资料多一下. 原文链接:https://www.w ...
- LintCode: Count and Say
C++ class Solution { public: /** * @param n the nth * @return the nth sequence */ string countAndSay ...
- ZH奶酪:Python按行读取文件
1:readline() file = open("sample.txt") while 1: line = file.readline() if not line: break ...
- Ubuntu IntelliJ IDEA 注冊碼與Gradle相關
一.Ubuntu IntelliJ IDEA 注冊碼 在线免费生成IntelliJ IDEA 15.0(16.+)注册码 注冊參考:https://www.iteblog.com/idea/ 依次选择 ...
- Fiber Channel SAN Storage
http://www.infotechguyz.com/VMware/FiberChannelSANStorage.html Using Fibre Channel with ESX/ESXi Fib ...