过度资源使用导致流程丧失

时间:2014-11-05 17:33:39

标签: php process dreamhost

今天我在控制台中测试了一些似乎在服务器端出现问题的脚本,对于某个文件,我得到了以下建议:

  

糟糕!你的一个进程(php,pid 15278)因资源使用过多而被杀死。   有关详细信息,请联系DreamHost支持。

好的,得到它,我应该升级我的托管,但我不清楚为什么有时会发生更明显的资源使用。

处理导致错误的文件的代码段生成了输出:

Iteration 1 Start
Memory Usage At the Start: 31,179.26Kbytes //Got with memory_get_usage
Memory Usage At the End: 26,350.64Kbytes
Duration:14
Iteration 2 Start

Yikes! One of your processes (php, pid 15278) was just killed for excessive resource usage.
Please contact DreamHost Support for details.

但是,使用另一个文件(更大的文件),我得到以下日志:

Iteration 1 Start
Memory Usage At the Start: 132,115.70Kbytes
Memory Usage At the End: 26,350.64Kbytes: 129,268.95Kbytes
Duration:34
Iteration 2 Start
Memory Usage At the Start: 131,368.04Kbytes
Memory Usage At the End: 129,287.41Kbytes
Duration:36
....

依旧......

问题是,为什么我总是得到第一个文件的相同错误,似乎使用更少的内存,而第二个完成其12次迭代而没有一个问题?有什么猜测吗?

更新:已添加代码

foreach ( $worksheets as $worksheet ){  
        $this->ultimo_apunte = NULL;
            for ( $i=1; $i < $worksheet["totalRows"]; $i+=self::$chunk_size ){
                echo "\Iteration".(($i-1)/250+1);
                $comienzo_iteracion = time();
                $filter = new ExcelReadFilter($i, self::$chunk_size);
                $reader->setReadFilter($filter);            
                $objPHPExcel = $reader->load($excel_file);
                $objPHPExcel->setActiveSheetIndexByName($worksheet["worksheetName"]);
                $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true);
                $c = 0;

                foreach ( $sheetData as $rowIndex => $row ){
                    if (!isset($apunte)) {
                        $apunte = Apunte::conFila($row);    
                        if ( $apunte->completo() ){
                            $apunte->ejercicio = "N/A";
                            fwrite($f, $apunte->insert_stmt());
                            $this->ultimo_apunte = $apunte;
                            unset($apunte);
                        }
                    }
                    else{
                        $apunte->completar($row);

                        if ( $apunte->completo() ){
                            $apunte->ejercicio = "N/A";
                            fwrite($f, $apunte->insert_stmt());
                            $this->ultimo_apunte = $apunte;
                            unset($apunte);
                        }
                    }
                }
echo "\nMemory Usage At the Start: ".number_format((memory_get_usage()/1024), 2)."Kbytes";  
                unset($sheetData);
                unset($objPHPExcel);    


echo "\nMemory Usage At the End: ".number_format((memory_get_usage()/1024), 2)."Kbytes";

                $fin_iteracion = time();
                $it_duration = $fin_iteracion - $comienzo_iteracion;
                $iteraciones_completadas+=1; 

                if ( !$process ) {
                    $process = new stdClass;
                    $process->start_time = date("Y-m-d");
                }

                if ( $iteraciones_completadas == 0 ){
                    $process->ellapsed_time = 0;
                }else{
                    $process->ellapsed_time = $fin_iteracion - strtotime($process->start_time);
                }

                $process->estimated_time = $process->ellapsed_time+$it_duration*($num_iteraciones - $iteraciones_completadas);
echo "\nDuration:".$it_duration."";
//log_string(ob_get_contents());        
//ob_clean();
                if ( method_exists($process, "saveToFile" )) $process->saveToFile();
        }
    }
    fclose($f);

global $db;

        $sql = "
            LOAD DATA LOCAL INFILE '".$db->real_escape_string($sql_file)."' 
            INTO TABLE apuntes
            FIELDS TERMINATED BY ',' 
            ENCLOSED BY '".'"'."' 
            ESCAPED BY '\\\'  
            LINES TERMINATED BY '\\n'
            (id_diario, fecha, asiento, apunte, cuenta, descripcion, concepto, debe, haber, es_apertura, es_cierre, ejercicio);
        ";

        error_reporting(0);
        $db->query($sql);

抱歉这个烂摊子......

0 个答案:

没有答案