0

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.?

kumaresan
  • 83
  • 1
  • 10
  • Please check this solution - it uses downloading the file piece by piece https://stackoverflow.com/questions/4000483/how-download-big-file-using-php-low-memory-usage After that You can use `file_get_contents($local_file)` on it. – Michal Przybylowicz Jun 09 '15 at 10:46

3 Answers3

2

You have a simple typo:

$json = file_get_contents($url);
$obj = json_decode($json);
Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
1

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);
monxas
  • 2,475
  • 2
  • 20
  • 36
0

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

or set bigger memory

samo
  • 1
  • 2