GaretJax / phpbrowscap

Standalone replacement for php's native get_browser() function
MIT License
429 stars 69 forks source link

Cache size #59

Open ghost opened 10 years ago

ghost commented 10 years ago

The size of browscap.ini has more than doubled in the last few months. Using v5024, the corresponding php cache file needs about 20M of RAM. We are using a stripped down version of that file in our WordPress plugin, wp SlimStat.

I was wondering if there was a way to split the cache into multiple files, and then loop through them to load only a subset of agents/browsers at a time.

Would you be able to explain the structure of _browsers and _patterns and how they work together to see if we can split them correctly?

mimmi20 commented 10 years ago

There are 4 arrays needed.

  1. _pattern: it holds the detection rules from the browscap file, but quoted to be able to use them with preg_match, the key in this array is the regex, the value is the key in the _browsers array
  2. _browsers: it holds the values from the browscap file, the property names are replaced with their keys from the _properties array, the property value of the parent property is replaced with their key of the _useragents array
  3. _properties: it holds the properties from the browscap file
  4. _useragents: it holds the values (names) of the parent property

I hope I explaned it right.

Could you tell what kind of browscap file you use (lite, normal or full) ?

ghost commented 10 years ago

What we ended up doing in WP SlimStat [ https://github.com/getusedtoit/wp-slimstat/tree/master/databases ] is to split the initial ini file into 5 chunks, and then run phpbrowscap on each of them to create the corresponding cache.php. Then we simply loop through the files until we find a match. Memory usage went from 20M to 2M!

mimmi20 commented 10 years ago

If you like, create a feature request on https://github.com/browscap/browscap to let you create these splitted files. Then dont need to do this after each update.