PHP5-FPM error "Fatal Error Unable to allocate shared memory segment"

I just got this error this morning when trying to run some php shell script:

"Fatal Error Unable to allocate shared memory segment"

I followed this following trick and it seemed to work:

1. Use ipcs -lm to determine current shared memory limits. And use ipcs -ma to determine how much shared memory is currently in use.

2. Increase maximum shared memory segment size from 32MB to 128MB.

echo "134217728" >/proc/sys/kernel/shmmax
echo "134217728" >/proc/sys/kernel/shmall

And then retry.

3. If php5-fpm then works ok, make the change survive reboots, by placing an entry in /etc/sysctl.conf as below:

kernel.shmmax=134217728
kernel.shmall=134217728