一段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. python3 验证码去噪

    处理前图像: 处理后图像 代码 #coding:utf8 import os from PIL import Image,ImageDraw,ImageFile import numpy import ...

  2. ESXI部署OVF模板提示用户已取消操作处理方法

    ESXI导出OVF部署到新的ESXI服务器上,Linux主机没有出现用户已取消操作的提示,部署WINDOW虚拟机的时候,提示用户已取消操作,如图: ​首先,要先了解为什么会出现这个问题,原因在于,在做 ...

  3. Excel长数字防止转换为科学计数法

    网上的一个方法是,加单引号,但是不好看. 我的处理,是先加,再替换成带格式的. strTable = Formater.SimpleTable(dt, "aaa", "| ...

  4. Creating OpenGL 4.3 window fails with GLFW3

      I set up a minimal application to open a blank window with GLFW3: #include <iostream> #inclu ...

  5. MFC获得当前用户等信息

    MFC获得当前用户等信息 #ifndef UNICODE #define UNICODE #endif #pragma comment(lib, "netapi32.lib") # ...

  6. Android 演示 Android ListView 和 github XListView(3-3)

    本文内容 环境 项目结构 演示 1:简单 XListView 演示 2:XListView + Fragment 演示 3:XListView + ViewPager + Fragment 本文三个演 ...

  7. linux测试工程介绍(Linux Test Project)

    http://ltp.sourceforge.net/ Linux Test Project, 后台很硬,由SGI™ 发起, IBM维护,所以质量有保障. 里面介绍了很多工具,对于一般的基准测试应该是 ...

  8. kendoUpload

    <style> .upfile { display: inline-block; width: %; } .upfile li { display: inline-block; width ...

  9. AT&T汇编和Intel汇编语法主要区别

    AT&T使用$表示立即操作数,而Intel的立即操作数是不需要界定的.因此,使用AT&T语法引用十进制值4时,使用$4,使用Intel语法时只需使用4.   AT&T在寄存器名 ...

  10. mysql版本导致的hibernate 方言问题

    今天在看hibernate视频时,看到视频上人家的hibernate.cfg.xml配置文件在配置hibernate方言时,发现视频上是这样写的<property name="dial ...