

How to Fix PHP's Most Annoying Error - 2upmedia
http://www.airpair.com/php/fatal-error-allowed-memory-size

======
lazyant
"Your first course of action is to increase your memory limit" \- No. First
thing you do is baseline your server and figure out how much max memory you
want to allocate to PHP given the maximum that can be used from the other
processes. OP's advice is a recipe for oom'ing your VPS. Also if there are
more developers, hiding the memory allocation in code instead of setting file
is going to be fun.

~~~
2upmedia
I mention: "never do these tests on a production server unless you’re sure you
have plenty of RAM and you fully understand how web server processes consume
memory. You could easily bring a server to its knees if there are many
concurrent processes running, each using a high amount of memory." It's a
temporary debugging procedure. The obvious goal to reduce memory usage.

Later on I say: "If by increasing the memory limit you have gotten rid of the
error and your code now works, you’ll need to take measures to decrease that
memory usage. Here are a few things you could do to decrease it:"

------
martin_
Setting a 1gb memory limit is a great way to hide the problem and dramatically
reduce the maximum number of concurrent requests to your website, and drain
resources from any other services running on the box(es).

~~~
laumars
Being massively pedantic for a moment; he didn't set the memory limit to 1GB
but instead to 0.9765625GB:

    
    
        <?php
            ini_set('memory_limit', '1000M'); // or you could use 1G
        ?>
    

Joking aside, do most people these days just use MB (1000^n) instead of MiB
(1024^n) when working with RAM? Is this now the standard way to calculating
memory?

~~~
2upmedia
Good call. Minor oversight. Just updated that. I think if your NOT a hardcore
technologist you probably think of megabytes as as 1000^n. It's really easy to
forget too for the rest of us.

~~~
derickr
Über-pedantry: It's "you're" and not "your".

~~~
2upmedia
Unfortunately, HN doesn't have an edit function for comments. ;)

~~~
laumars
It does, but only for comments that haven't been replied to

~~~
2upmedia
More pedantry ;)

~~~
laumars
I was actually trying to be helpful there :(

~~~
2upmedia
Hehe. Based on the previous pendantry, it blended in. I'll take it as help
then. :D

~~~
laumars
The previous pedantry wasn't me though; only the MiB / MB comment. And that
was partly out of curiosity if 1000MB == 1GB was a deliberate rounding.

------
trebor
This should be titled "how to find a memory leak". It's a very basic article
on memory management and how to find a memory leak.

~~~
laumars
It's not technically a memory leak though. It's more to do with finding errors
in your code that use unexpectedly large quantities of memory. But since
everything is being allocated and deallocated correctly, you're not actually
leaking any memory (which I guess you could argue, makes the article even more
basic).

In any case, you're right that the title is a little misleading, but pedantry
aside, it's still a useful resource.

------
serve_yay
Good lord.

------
stevejpurves
fixing things like this often means going round the houses, nice to have a
debugging checklist like this!

