Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Google Mike
July 22, 2004, 11:58 pm
rate this thread
you're wondering). I was using shared memory (shm* API) a great deal
in my web applications because I have 1GB of RAM on this system. By
using shared memory, I can optimize web pages a little by not having
to hit the database every time I want to regurgitate a somewhat-static
You may be familiar with the API that looks like this:
$key = 'My Key';
$value = 'My Value';
$app = 'lovelyapp'; //lovelyapp would be the fake name of my web app
$key = $key . '1.5'; //1.5 was the version of my web app, to provide
$segment_key = abs(crc32($app . $key));
$segment_size = 1024;
$segment_perms = 0600;
$shm_id = shm_attach($segment_key, $segment_size, $segment_perms);
shm_put_var($shm_id, $app . $key, $value);
This was working rather beautifully for me until I started messing
with the '1.5' literal. The reason, I suspect, was that I had been
using the app (without a bounce of httpd or entire server) and storing
stuff in shared memory with keys of 1.3, 1.4, 1.5, and 1.51 as my app
went through various revisions. This allowed different versions of the
app to simultaneously exist on the same web server and have an
exclusive section of shared memory.
I didn't think I was storing a tremendous amount of stuff there --
perhaps no more than 1MB per shared memory section (determined by
Finally, *KABOOM* my web app died with the error "Not enough space on
device" and pointed out the error was on the line where I used
So, I thought -- no problem -- no one using the app this late, so I'll
just bounce the web server (httpd). I did and the error still occured.
I thought, okay, clear my local browser cache and try again. Nope --
still occurred. I tried to bounce httpd again and even go straight to
the web server itself and see if a web page would have the same error.
Yep -- it had the same error no matter what I did.
I had no choice but TO REBOOT THE ENTIRE LINUX WEB SERVER. This
definitely cleared up the problem and I've now hammered on that server
for awhile now with the web app and all looks well.
What's your diagnosis? And, why didn't bouncing httpd clear it up
since Apache spawns PHP as a child process and PHP spawns shared
memory as a child process -- at least I thought it did?
Re: Shared Memory Limit?
On 07/22/2004 10:58 PM, Google Mike wrote:
Sometimes when an Apache process dies the shared memory it allocated is
not removed. It is like a file. In Linux, just ipcs and ipcrm commands
to list and remove lost shared memory blocks.
BTW, using shared memory for that caching purposes may lead to that
problem if you have to many blocks to cache. It is probably better to
use file based caching as usually there is much more space available and
is easier to garbage collect.
For generic content I use this file based cache class:
PHP Classes - Free ready to use OOP components written in PHP
PHP Reviews - Reviews of PHP books and other products
Metastorage - Data object relational mapping layer generator
- » can php respond to events? (immediately respond when and SMS is received)
- — Previous thread in » PHP Scripting Forum