Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory exhausted #68

Open
theblackwidower opened this issue Aug 29, 2014 · 12 comments
Open

Memory exhausted #68

theblackwidower opened this issue Aug 29, 2014 · 12 comments

Comments

@theblackwidower
Copy link

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.

@sidwubf
Copy link

sidwubf commented Oct 17, 2014

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

@ghost
Copy link

ghost commented Oct 17, 2014

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

@ghost
Copy link

ghost commented Oct 17, 2014

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
Copy link

ghost commented Oct 18, 2014

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]

@zergtant
Copy link

zergtant commented Nov 9, 2014

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.

@DaAwesomeP
Copy link
Contributor

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
Copy link
Contributor

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.

@brendo
Copy link

brendo commented Apr 23, 2015

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 👍

@mimmi20
Copy link

mimmi20 commented Apr 23, 2015

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

@brendo
Copy link

brendo commented Apr 23, 2015

Looks like the issues have been fixed in another port

@hamburger123456
Copy link

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();

@mzvarik
Copy link

mzvarik commented Nov 27, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants