apache - 我所有脚本中的 PHP 内存不足

标签 apache memory php

编辑:

我的 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)

所以我有一个写得不是很好的 PHP 脚本,当我执行它时,PHP 内存不足,我的电脑死机了。在运行脚本之前,我增加了 php.ini 中的内存限制。之后我把它改回了默认值。

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

似乎我之前提到的那个糟糕的脚本仍然以某种方式在后台运行。

我已经重新启动了 PHP、Apache,我已经重新启动了我的 PC,甚至睡了 8 个小时。第二天早上,我发现所有 PHP 脚本仍然内存不足。什么鬼?

我现在到处都会遇到这样的错误(当然错误中的文件会发生变化)——每一个甚至是最简单的 PHP 脚本:

Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 6144 bytes) in D:\data\o\WebLib\src\Db\Db.php on line 241

Fatal error (shutdown): Allowed memory size of 262144 bytes exhausted (tried to allocate 6144 bytes) in D:\data\o\WebLib\src\Db\Db.php on line 241

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

<?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);
//}

最佳答案

更改 php.ini :

memory_limit = 256M

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

关于apache - 我所有脚本中的 PHP 内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4825784/

相关文章:

iphone - 使用performSelectorInBackground运行加载指示器

php - 如何更改 WAMPSERVER 中的 'ft_min_word_len'?

PHP代码没有被执行,但是代码显示在浏览器源代码中

javascript - 为什么当我在 Apache 上运行我的 react 构建时......只出现空白页面..?

apache - Mod重写问题

javascript - 加载特定于代码点火器 View 的独特 JavaScript 文件

php - 插入数据库时​​需要识别动态输入/文本区域

php - codeigniter - 升级 php 和 apache 后未找到 fatal error 类 'CI_Controller'

c++ - 如何存储 while 循环中产生的数据?

c - C语言中如何获取内存地址的值