PHP在我的所有脚本中耗尽内存

Ric*_*nop 2 php memory apache

编辑:

我的php.ini有256MB内存集:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 250     ; Maximum execution time of each script, in seconds
max_input_time = 120    ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 256MB    ; Maximum amount of memory a script may consume (256MB)
Run Code Online (Sandbox Code Playgroud)

所以我有一个PHP脚本编写得不是很好,当我执行它时,PHP内存不足,我的PC冻结了.在运行脚本之前,我已经增加了php.ini中的内存限制.之后我将其更改回默认值.

现在问题是它似乎已经为我的PHP安装做了一些事情.我现在执行的每个PHP脚本都告诉我它没有足够的内存.以前运行过的脚本没有问题.

看起来我之前提到的一个糟糕的脚本仍然在某种程度上在后台运行.

我重新启动了PHP,Apache,我重新启动了我的电脑,甚至睡了8个小时.接下来的事情我发现所有的PHP脚本仍然没有内存.我勒个去?

我现在到处都是这样的错误(当然错误更改中的文件) - 每一个甚至最简单的PHP脚本:

致命错误:第241行的D:\ data\o\WebLib\src\Db\Db.php中允许的内存大小为262144字节(试图分配6144字节)

致命错误(关闭):第241行的D:\ data\o\WebLib\src\Db\Db.php中允许的内存大小为262144字节(试图分配6144字节)

好的是脚本(我已经注释掉了坏的部分):

<?php 

error_reporting(E_ALL);

define('BASE_PATH', dirname(__FILE__));
require_once(BASE_PATH.'/../WebLib/config/paths.php');             

require_once(PATH_TO_LIB3D_SRC.'/PHPExcel/Classes/PHPExcel.php');
require_once(PATH_TO_LIB3D_SRC.'/PHPExcel/Classes/PHPExcel/Reader/IReadFilter.php');

///**  Define a Read Filter class implementing PHPExcel_Reader_IReadFilter  */ 
//class chunkReadFilter implements PHPExcel_Reader_IReadFilter {     
//  private $_startRow = 0;     
//  private $_endRow = 0;     
//  /**  Set the list of rows that we want to read  */ 
//    public function setRows($startRow, $chunkSize) 
//    { 
//        $this->_startRow    = $startRow; 
//        $this->_endRow      = $startRow + $chunkSize;     
//    } 
//    public function readCell($column, $row, $worksheetName = '') 
//    {         
//      //  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow 
//        if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { 
//            return true;         
//        }         
//        return false;     
//    } 
//} 
//
//function ReadXlsxTableIntoArray($theFilePath)
//{ 
//  $arrayData                  = 
//  $arrayOriginalColumnNames   = 
//  $arrayColumnNames           = array();
//  
//  $inputFileType = 'Excel2007';
//  /**  Create a new Reader of the type defined in $inputFileType  **/
//  $objReader = PHPExcel_IOFactory::createReader($inputFileType);
//  /**  Define how many rows we want to read for each "chunk"  **/ 
//  $chunkSize = 10; 
//  /**  Create a new Instance of our Read Filter  **/ 
//  $chunkFilter = new chunkReadFilter(); 
//  /**  Tell the Reader that we want to use the Read Filter that we've Instantiated  **/ 
//  $objReader->setReadFilter($chunkFilter);
//  $objReader->setReadDataOnly(true);
//  /**  Loop to read our worksheet in "chunk size" blocks  **/ 
//  /**  $startRow is set to 2 initially because we always read the headings in row #1  **/
//  for ($startRow = 1; $startRow <= 65536; $startRow += $chunkSize) {
//      /**  Tell the Read Filter, the limits on which rows we want to read this iteration  **/ 
//      $chunkFilter->setRows($startRow,$chunkSize); 
//      /**  Load only the rows that match our filter from $inputFileName to a PHPExcel Object  **/ 
//      $objPHPExcel = $objReader->load($theFilePath); 
//      //    Do some processing here
//      
//      $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
//      foreach($rowIterator as $row){
//          
//          $cellIterator = $row->getCellIterator();
//          //$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
//          if(1 == $row->getRowIndex ()) {
//              foreach ($cellIterator as $cell) {
//                  $value = $cell->getCalculatedValue();
//                  $arrayOriginalColumnNames[] = $value;
//                  // let's remove the diacritique
//                  $value = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $value);
//                  // and white spaces
//                  $valueExploded = explode(' ', $value);
//                  $value = '';
//                  // capitalize the first letter of each word
//                  foreach ($valueExploded as $word) {
//                      $value .= ucfirst($word);
//                  }
//                  $arrayColumnNames[] = $value;
//              }
//              continue;
//          } else {
//              $rowIndex = $row->getRowIndex();
//              reset($arrayColumnNames);
//              foreach ($cellIterator as $cell) {
//                  $arrayData[$rowIndex][current($arrayColumnNames)] = $cell->getCalculatedValue();
//                  next($arrayColumnNames);
//              }
//          }
//          
//          unset($cellIterator);
//      }
//      
//      unset($rowIterator);
//  }
//  
//  // Free up some of the memory 
//  $objPHPExcel->disconnectWorksheets(); 
//  unset($objPHPExcel); 
//  
//  return array($arrayOriginalColumnNames, $arrayColumnNames, $arrayData);
//}
//
//if (isset($_POST['uploadFile'])) {
//  //list($tableOriginalColumnNames, $tableColumnNames, $tableData) = ReadXlsxTableIntoArray($_FILES['uploadedFile']['tmp_name']);
//  //CreateXMLSchema($tableOriginalColumnNames, 'schema.xml');
//  //echo GetReplaceDatabaseTableSQL('posta_prehlad_hp', $tableColumnNames, $tableData);
//}
Run Code Online (Sandbox Code Playgroud)

yod*_*oda 5

更改php.ini:

memory_limit = 256M
Run Code Online (Sandbox Code Playgroud)

请注意,您不应该使用MBKB,而是使用MK.