Memory exhausted error for json_parse with PHP Memory exhausted error for json_parse with PHP json json

Memory exhausted error for json_parse with PHP


THIS IS A VERY BAD IDEA, that said, you'll need to set

ini_set('memory_limit',filesize($FILE) + SOME_OVERHEAD_AMOUNT);

because you're reading the entire thing into memory. You may very well have to set the memory limit to two times the size of the file since you also want to JSON_DECODE

NOTE THAT ON A WEB SERVER THIS WILL CONSUME MASSIVE AMOUNTS OF MEMORY AND YOU SHOULD NOT DO THIS IF THE FILE WILL BE MANY GIGABYTES AS YOU SAID!!!!

Is it really a giant JSON blob? You should look at converting this to a database or other format which you can use random or row access with before parsing with PHP.


I've given all my servers a memory_limit of 100M... didn't run into trouble yet.

I would consider splitting up that file somehow, or get rid of it and use a database