Reputation: 1607
JSON file name: testjsonfile.json
Size of the "testjsonfile.json" is 2GB.
How to load json file? Code:
$data = json_decode(file_get_contents(testjsonfile.json'), TRUE);
print_r($data);
Error:
Fatal error: Out of memory (allocated 1310720) (tried to allocate 1719707520 bytes) in test.php
Note: Increased memory limit
ini_set('memory_limit', '4000M');
Upvotes: 0
Views: 1238
Reputation: 18550
Use something similar to https://github.com/salsify/jsonstreamingparser
This streams the data in so will use less total memory rather than having everything in memory
Upvotes: 2
Reputation: 4066
set_time_limit(0);
ini_set('memory_limit', '20000M');
To the top of your script. Change the 20000M accordingly.
Upvotes: 0