2016-06-24 50 views
0

的設置致命錯誤:在對存儲器(分配524288)(試圖分配4294967293個字節)

服務器:Win7的
數據庫:的MSSQLServer 2012
Web服務器:IIS
PHP:5.5
連接:$driver="Driver={SQL Server Native Client 11.0}

SELECT auditid, Datalength(comments) 
FROM tblAudit 
ORDER BY 2 desc 

278 33152 (Equates to 16576 characters when viewing in Notepad++) 
239 22308 (Equates to 11186 characters when viewed in Notepad++) 

php memory settings 
ini_set("memory_limit", "-1"); 

PHP

$Comments = odbc_result($rsAudit,"Comments"); 

工作正常,22308字符串長度

隨着33152

Fatal error: Out of memory (allocated 524288) (tried to allocate 4294967293 bytes) in D:\Inetpub\wwwroot\TramsWeb\php\auditsummary.php on line 235 

16,576似乎並不像很多人物在一個去選擇的,但它崩潰的PHP。

任何人都可以建議解決這個問題?

+0

你應該開始想知道爲什麼PHP是試圖分配2^32-3字節,而不是差異22304至33152之間...... –

回答

0

我打算從查看運行32位PHP的數字4294967293開始猜測,它會遇到所有32位內容受限的最大內存限制錯誤4GB。

0

對我來說,它看起來像一個PHP的錯誤。應該不需要分配這麼多的內存,只是爲了從數據庫中收集一個長字符串。

建議遷移到64位php是一個好主意。不過,我不願意這樣做,因爲它需要客戶端這樣做,而且他們還有其他依賴關係。

我已經設計了選擇在4K數據塊的數據,然後件他們一起解決方法:

function get_comments ($conn,$AuditID,$chunksize,$chunks) 
# NRE 24-Jun-2016 
# If comments contains over 22308 characters, 32 bit php crashes attempting to collect comments in one go 
# Workaround is to split select into chucks then piece them to gether 
# Chunksize : size of chunk of data to be grabbed in one go. Testing has indicated can be more more than 4K 
# $chunks : Number of sections that comments need to be split into to get all the data 
{ 
    $sSql ="SELECT "; 
    $x = 1; 
    $lStart=$x; 
    $lEnd=$chunksize; 
    # Loop round specified number of chunks, building up sql to collect chunks of the data 
    while($x <= $chunks) { 
    if ($x>1) { 
     # If not first chunk, add comma to split chunk selects 
     $sSql = $sSql.", "; 
    } 
    # SUBSTRING chunk size bit of the data. Alias provided for clarity; is not actively used 
    $sSql = $sSql."SUBSTRING(comments, ".$lStart.",".$chunksize.") comments".$x."\r\n"; 
    $lStart=$lStart+$chunksize; 
    $lEnd = $lEnd+$chunksize; 
    $x++; 
    } 
    # Complete the sql 
    $sSql = $sSql." FROM tblAudit WHERE AuditID = ".$AuditID; 
    $rs = odbc_exec($conn, $sSql); 
    while(odbc_fetch_row($rs)){ 
    $x=1; 
    while($x <= $chunks) { 
     $Comments = $Comments.odbc_result($rs,$x);  
     $x++; 
    } 
    }  
    # Return the completed comments 
    return $Comments; 
} 
相關問題