一段PHP程序执行报错:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)

去百度了一下,原来是php.ini中的内存分配的问题,默认php代码能够申请到的最大内存字节数就是134217728 bytes,如果代码执行的时候再需要更多的内存,就会报错了,于是就将php.ini文件中的配置改了一下:

代码如下:

memory_limit = 128M;//将128M改成了256M

但是之后一想,一个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)的更多相关文章

  1. 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 ...

  2. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes) in

    最近莫名出现这个错误. 研究一下原因很奇葩呢. 原因:sql获取数据库中数据,取出数据赋给变量,数据太多,超过memory_limit内存设置了. 解决方法:设置memory_limit不建议.优化代 ...

  3. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in

    解释是可用内存已耗尽,这关系到PHP的memory_limit的设置问题. 我在网上看到,有两种方法解决 1.修改php.ini memory_limit = 128 这种方法需要重启服务器,很显然, ...

  4. 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 从数据库 ...

  5. Fatal error: Allowed memory size of 8388608 bytes exhausted

    这两天安装bugfree,更换了一个数据量较大的库,结果打开bug详情页要么是空白页,要么就报如题的错误,错误信息还包括C:\wamp\www\bugfree\Include\Class\ADOLit ...

  6. (转载)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 ...

  7. Allowed memory size of 134217728 bytes exhausted解决办法(php内存耗尽报错)【简记】

    报错: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) i ...

  8. php的Allowed memory size of 134217728 bytes exhausted问题解决办法

    php的Allowed memory size of 134217728 bytes exhausted问题解决办法 报错: Fatal error: Allowed memory size of 1 ...

  9. 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 ...

随机推荐

  1. Android -- WebView进度条

    有系统actionbar requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//先给Activity注册界面进度条功能 setCo ...

  2. wget获取整站

    wget -m -e robots=off https://www.baidu.com -m是克隆整个网站,-e robots=off是让wget忽视robots.txt 如果网站有中文路径,最好用以 ...

  3. ZH奶酪:哈工大LTP云平台标记含义及性能

    从官网搬过来的 囧rz 哈工大讯飞语言云 由哈工大 和科大讯飞 联合研发的中文自然语言处理云服务平台.结合了哈工大“语言技术平台——LTP” 高效.精准的自然语言处理核心技术和讯飞公司在全国性大规模云 ...

  4. 使用Chrome保存网页为mht文件

    一直在使用chrome浏览器,但由于需要将部分网页保存为mht文件,却发现chrome默认不支持.chrome浏览器默认支持2种:单独的html文件,全部: 万能的chrome怎么可能保存不了mht? ...

  5. 微信小程序 - 自定义swiper dots样式(非组件)

      自定义须知: :组件内无法使用自定义样式变化,需要自定义 :原理就是利用swiper change事件与下标index匹配,显示不同的样式 swiper组件须知: :一旦swiper用于组件化,就 ...

  6. 关于LINUX在中断(硬软)中不能睡眠的真正原因

    摘自http://bbs.chinaunix.net/thread-2115820-1-1.html 4楼的回答 先把中断处理流程给出来 1.进入中断处理程序--->2.保存关键上下文----& ...

  7. SQL Server排序规则不一致 - Collate Database_Default

    http://www.cnblogs.com/chencidi/archive/2014/07/02/3820386.html 使用多库查询时会出现排序规则冲突的问题 解决办法 在字段后面添加Coll ...

  8. Cocos开发中可能会遇到的问题

      开发中碰到的问题及解决方案: 1:场景工程中没有被依赖关联的图片声音或者其它资源,导出到微信后找不到 有些在场景工程中没有指定而通过代码中动态加载的资源,cocos creator不会导出到发布目 ...

  9. SpringBoot使用JSP渲染页面

    1.pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...

  10. C/C++中extern关键字详解(转)

    1 基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义.此外extern也可用来进行链接指定. 也就是说extern ...