2011-01-28 61 views
2

編輯: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,我已經重新啓動我的電腦,甚至睡了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); 
//} 
+0

我們能看到劇本嗎? – yoda 2011-01-28 07:17:52

+0

你不能在php.ini中增加允許的內存大小嗎 – Gaurav 2011-01-28 07:21:51

+0

看起來很清楚你的內存設置不正確。嘗試在您的配置中使用「256M」而不是「256MB」。 – 2011-01-28 07:31:28

回答

5

更改爲php.ini:

memory_limit = 256M 

請注意,你不應該使用MBKB,但中號ķ

3

你有256Kmemory_limit。在幾乎所有情況下,這個數字都大大降低。默認值是16M(自5.2開始)。

+0

我在php.ini中設置了256MB的內存,這似乎很奇怪。我不明白。檢查我的帖子我添加了我的php.ini的摘錄。 – 2011-01-28 07:25:18

3

你確定你正確地設置你的內存大小嗎?該錯誤顯示您的最大內存爲262144 bytes,這是MB的四分之一。這真的很低!

至於反應到你的PHP設置:不應該是語法是

memory_limit = 256M 

我不知道它是否接受M和MB,但它可能不是?

1

嘿理查德。由於PHP明確聲明您只有256K設置爲限制,因此無法執行更改。瀏覽php.ini和其他所有地方。它可能位於虛擬主機上的.htaccess文件中。

1

你有沒有重新啓動Apache的你編輯php.ini後增加了memory_limit = 256MB

4

PHP預計單位兆字節由單個字母M表示。您已指定256MB。注意額外的B

由於PHP不理解單元MB,它回落到最低的已知的「命名」單位:千字節(ķ)。

只要從設置中刪除多餘的,它應該正確讀取數值爲256兆字節(256M

請參閱有關數據大小單位以下FAQ條目:

PHP: Using PHP - Manual