zoukankan      html  css  js  c++  java
  • 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文件中的配置改了一下:

    代码如下:

    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; } }

    完毕。

  • 相关阅读:
    使用Dictionary键值对判断字符串中字符出现次数
    Linq实现字符串拼接多条件查询
    js数据类型转换
    js前端数据类型检测typeof,instanceof,Object.prototype.toString.call
    moment.js格式化日期,获取前一个月的时间
    css 样式中height100%失效问题
    记一次react项目运行崩溃
    null和undefined区别
    windows腾讯云/阿里云服务器更换操作系统为linux
    csrf攻击原理和防御-生成token防御代码
  • 原文地址:https://www.cnblogs.com/zl0372/p/php_error.html
Copyright © 2011-2022 走看看