phpbrowscap icon indicating copy to clipboard operation
phpbrowscap copied to clipboard

Memory exhausted

Open theblackwidower opened this issue 9 years ago • 12 comments

So, I just decided to test out this little toy on my personal server, and I ran into a bit of an issue. This is the message I got:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /var/www/html/modules/Browscap.php on line 818

What exactly are you trying to do!? You may ask. Well, nothing more nor less than what was shown in the quick start guide.

On a likely related note, the cache folder. I'm not sure what it's supposed to do, but I created it, and directed the script to it, and unlocked it for full access (777), and yet nothing is filling it. I run the script, but I get the above error, and the folder remains empty.

Am I doing something wrong, or is this an error in the class?

Thank you for your time.

theblackwidower avatar Aug 29 '14 05:08 theblackwidower

I got the same problem. I think it just change the "browscap.ini" to array. And the memory exhausted. Hope fix it.

sidwubf avatar Oct 17 '14 01:10 sidwubf

I have the issue too, looking into it now...

ghost avatar Oct 17 '14 22:10 ghost

Well, I had a plaster/bandaid fix for line 818, but that only shifted another memory issue to line 504! The fix was:

// Get updated .ini file
$browscap = $this->_getRemoteData($url);

// Chunk FIX
$bc_chunks = [];
$browscap = str_split($browscap, 25000);
foreach ($browscap as $chunk) $bc_chunks = array_merge($bc_chunks, explode("\n", $chunk));
$browscap = $bc_chunks;
// Chunk FIX

// $browscap = explode("\n", $browscap); --- removed for FIX

Alternatively, bump up your memory if you can (need access to php.ini)... 512MB worked.

To summarise, the INI file is HUGE

ghost avatar Oct 17 '14 22:10 ghost

Guys, stop it right there! More memory won't do and trying to download on live system is not recommended because the file is way to large and will never stop to get large. Best to follow the original developer advise: cron the update and all should be ok. Cache folder needs 774 and chown to root:www-data ( Php identity ). We forked this pack and tweaked the construction method for more verification of the cache folder and set autoupdate to false. No more memory problem. Please see jean-lelarge/phpbrowscap [email protected]

ghost avatar Oct 18 '14 08:10 ghost

ini_set('memory_limit', '-1'); overrides the default PHP memory limit. and before you run frist time use $bc->updateCache() to make cache. then you can remove ini_set('memory_limit', '-1'); this is my fix.

zergtant avatar Nov 09 '14 15:11 zergtant

Expanding the available memory is very dangerous. PHP could suck up memory normally used by other processes or simply grow uncontrollably until the system crashes. Also, setting the INI means that your instance of PHP will have full access to it, which is a security risk. Lastly, setting the INI affects all PHP processes and scripts, not just the one that browscap is being used in.

On Nov 9, 2014, at 9:15 AM, "hengtao tantai" [email protected] wrote:

ini_set('memory_limit', '-1'); overrides the default PHP memory limit. and before you run frist time use $bc->updateCache() to make cache. then you can remove ini_set('memory_limit', '-1'); this is my fix.

— Reply to this email directly or view it on GitHub.

DaAwesomeP avatar Nov 09 '14 18:11 DaAwesomeP

Another idea is to use another CLI program like curl or wget to download the browscap file. It should have no problem with the file.

The chunk loading is also great. Either way, the downloading should be done through cron. If the download crashes, then it won't affect the client loading a page. Also, the client's page loading won't be slowed due to browscap downloading. I have experienced that multiple times.

DaAwesomeP avatar Nov 09 '14 19:11 DaAwesomeP

Currently using the workaround described by @zergtant to get this going. I feel this should be documented somewhere more officially though. Better still, it'd be a neat to include a script that could be used via cron to get/update this file :+1:

brendo avatar Apr 23 '15 03:04 brendo

If you the library from browscap/browscap-php and create the issues there, they may be fixt earlier.

mimmi20 avatar Apr 23 '15 07:04 mimmi20

Looks like the issues have been fixed in another port

brendo avatar Apr 23 '15 07:04 brendo

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 131072 bytes) in /www/XYZ/scripts/Browscap.php on line 833

500MB not enought? Whats to do? My cronJob: use phpbrowscap\Browscap; ini_set('memory_limit', '512M'); require 'scripts/Browscap.php'; $browscap = new Browscap('/www/XYZ/cache'); $browscap->updateCache();

hamburger123456 avatar Nov 17 '15 12:11 hamburger123456

I have the same problem... doesn't work.

mzvarik avatar Nov 27 '18 03:11 mzvarik