2016-12-05 150 views
0

我用我的腳本這個API(https://api.ssactivewear.com/v2/products/):內存分配問題後,增加內存限制

ini_set('memory_limit', "300M"); 
$uri=$end_url.$method; 
$ch = curl_init($uri); 
$access_key=base64_encode($customer_number.':'.$api_key); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $access_key)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
$retrive_response = curl_exec($ch); 
curl_close($ch); 
return $retrive_response; 

腳本的幾個時間執行後,我收到一個錯誤

Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 161956814 bytes)

+0

您可以通過使用'echo ini_get(「memory_limit」)來檢查內存限制是否實際增加了。看到相關的帖子http://stackoverflow.com/questions/5061917/ini-setmemory-limit-in-php-5-3-3-is-not-working-at-all 還要確保它在腳本的頂部,並記住增加只針對正在運行的腳本 –

回答

0

似乎你的腳本需要比300M更多的內存。嘗試

ini_set('memory_limit', "600M"); 
+0

我已經將內存從166增加到了256,並且面臨了問題。致命錯誤:允許內存大小268435456字節耗盡(試圖分配161985171字節) –

+0

@NeerajMahajan加'echo memory_get_usage(); exit();'在'curl_exec'行之前。你會知道已經使用了多少內存。然後在腳本結尾嘗試相同的內容,但不使用'curl_exec'。它可以幫助您確定腳本的哪一部分消耗所有內存。如果值很小,那麼'curl_exec'需要更多的內存。一次又一次地增加它。 – rNix

+0

當添加'echo memory_get_usage();飲食'); '在curl_exec結果爲3978256之前,curl_exec結果爲'致命錯誤:內存不足(分配166199296)(試圖分配161956783字節)' –