Is there anyway I can open the file but just read and store the “Chicago” array elements in a variable? The reason I am asking is because The file many contain a huge list of arrays and reading the entire array and dumping them in the memory wont be a good idea. So how can we accomplish this?
You could mess around with using fseek(), but without reliably knowing where to seek to, it might be pointless. Either way I wanted to mention it. There are a few comments in the PHP manual that may help: http://us1.php.net/fseek
Thanks for the reply guys. I was thinking of a way to maintain a separate file that would play the role of indexing the data. Just like a file pointer which knows where to seek to just what “phpMyDirectory” suggested. For example, I’d query the index file to know exactly which position to seek to and then open the .json file with the pointer exactly to that position.
Any idea you can think this could be made possible?
XMLReader will allow loading one element at a time. You still need to scan sequentially. If you want random access to a large set of data then use a database.
The reason for this is due to PHP is extremely ineffective when doing file manipulations compared to many other languages.
With that said, the important factor here is how often do you plan to execute this scan/parse, and on how large data set.
In the end you have two options:
Convert the data and insert in the database.
If the data set is manageable, keep accessing it file based.
On both of these options you want to add another step, Caching. Though this would be even more important to add if you go with the second option.
So basically if it exist in cache, we don’t look it up again etc. Using this you can even access larger data set as files, since you only do it from time to time, instead of every time the data is required.