0

I am using this API (https://api.ssactivewear.com/v2/products/) in my script:

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;

After few time execution of script i have received an error

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

James Z
  • 12,209
  • 10
  • 24
  • 44
  • you can check if the memory limit was actualy increased by using 'echo ini_get("memory_limit"); See related post http://stackoverflow.com/questions/5061917/ini-setmemory-limit-in-php-5-3-3-is-not-working-at-all Also make sure it's on top of your script, and remember the increase is only for the running script – Louis Loudog Trottier Dec 05 '16 at 05:01

1 Answers1

0

It seems your script needs more memory than 300M. Try

ini_set('memory_limit', "600M");
rNix
  • 2,457
  • 1
  • 22
  • 28
  • I have already increased the memory from 166 to 256 upto 300 and face issue . Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 161985171 bytes) – Neeraj Mahajan Dec 05 '16 at 06:33
  • @NeerajMahajan add `echo memory_get_usage(); exit();` before the line with `curl_exec`. You will know how much memory already used. Then try the same in the end of your script but without `curl_exec`. It can help you determine which part of your script consumes all memory. If the value is small, then `curl_exec` need more memory. Increase it again and again. – rNix Dec 05 '16 at 06:41
  • When add `echo memory_get_usage(); die('t'); ` before the curl_exec result is 3978256 and after curl_exec add result is ` Fatal error: Out of memory (allocated 166199296) (tried to allocate 161956783 bytes)` – Neeraj Mahajan Dec 05 '16 at 07:25
  • @NeerajMahajan which line of code triggers error? `$retrive_response = curl_exec($ch);` this one? – rNix Dec 05 '16 at 07:33
  • when i place the code echo memory_get_usage(); die('t'); after curl_exec($ch) and shows fatal error Out of memory (allocated 166199296) (tried to allocate 161956783 bytes) – Neeraj Mahajan Dec 05 '16 at 08:32
  • @NeerajMahajan Can you open `$uri` in your browser with your credentials (`$customer_number` as login, `$api_key` as password), save the result into a file and check the size of this file? – rNix Dec 05 '16 at 09:00