0

OK, so here's what I'm trying to do :

  • I've got a large (~ 25MB) json file.
  • I'm opening it (with file_get_contents)
  • And then try to json_decode it

However, after a while a message pops up, notifying me that the memory has been exhausted :

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in...

Any ideas of a workaround?

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • have you tried it ini_set('memory_limit','12G'); – Rohit Choudhary Jun 19 '14 at 09:56
  • Perhaps you should switch to a file format which can be decoded progressively more easily, like XML. Or find a library that decodes a JSON file little by little as needed (not sure that exists, for PHP). Or use "JSON lines" format, in which you put individual JSON objects on individual lines, so you can read them one by one. – deceze Jun 19 '14 at 10:00
  • @RohitKumarChoudhary Well, I just did. But all it does is to increase the limit at which it crashes. :S – Dr.Kameleon Jun 19 '14 at 10:00
  • @deceze Well, I've been thinking about that. In any case, this huge .json file is nothing but a database (one that I was initially using, without issues, in a Cocoa/OSX app and decided to transfer to web). So, an alternative faster format will be needed at some point. (Perhaps transferring the whole thing to MySQL?) - but even then I'll have to somehow parse the json... – Dr.Kameleon Jun 19 '14 at 10:02

0 Answers0