Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in PHP

1.4k views Asked by At

I am facing issue in my code, when I am trying to store the file_get_contents output into an obj.

$json = file_get_contents($url);
$obj = json_decode($obj);

I am not allowed to change the memory size in ini.php because it is on server.Any other solution for this.?

3

There are 3 answers

1
Alex Tartan On

You have a simple typo:

$json = file_get_contents($url);
$obj = json_decode($json);
0
monxas On

Have you tried other options of increasing memory limit? Like

ini_set('memory_limit', '-1'); //change the -1 to a value that acommodates to your use case
$json = file_get_contents($url);
$obj = json_decode($json);
0
samo On

ini_set('memory_limit', '256M');

or set bigger memory