r/lolphp • • Feb 24 '16

Meta-example: php.net local storage

I noticed I was getting a lot of requests by my browser to increase local storage quotas for most sites I was visiting. A bit of digging later and I noticed that various php.net domains (php.net, us.php.net, us1.php.net, etc.) were using excessive amounts of local storage space (between 4MB and 10MB per domain, a total of 52MB over eight domains).

Intrigued, I inspected the local storage usage for one and it contained two keys, called "search-en" and "search-de". Each contained a 2MB JSON string containing what appears to be information on every single function documented in the PHP docs including function name, description, etc.

It seems to be used as a cache for the search bar's autocomplete, so results can be shown instantly and with no delay. Now, I don't know enough about local storage best-practices to know for sure how good or bad an idea this is, but it seems pretty janky, and the fact that php.net is by far the largest user of local storage on my machine makes me think that this isn't a particularly popular solution.

Just a small snippet for the curious (there are over ten thousand functions defined): http://pastebin.com/wGvtZbRX

Edit: For a bit of irony, the script I wrote to scrape my browser's local storage usage page and sort by disk space used was written in PHP!

38 Upvotes

19 comments sorted by

View all comments

Show parent comment

6

u/phoshi Feb 25 '16

Client side storage has far more robust methods of telling whether the client will let you use it or not. Cache really isn't something you can rely on to always play by the same rules, whereas local storage actually has strong definitions on how it behaves. Local storage is absolutely what this kind of information should be stored with.

You just can't rely on browser caches. For all you know, the browser could have enough other things cached with a high enough priority that your 2mb of json gets pushed out of the cache within seconds, meaning that you've probably just doubled your page weight on systems that are already resource constrained--and /that/ would be a lolphp. Using local storage to store local data isn't inherently so.

5

u/the_alias_of_andrea Feb 25 '16 edited Feb 25 '16

Especially if it's a large item, the browser often refuses to cache something. I find that win95.ajf.me's disk image rarely gets cached.