By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Shared Memory Limit?

P: n/a
I'm using PHP 4.2.2 on RH9 Linux (with Progeny.com updates, in case
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
reference table.

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
uniqueness
$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);
shm_detach($shm_id);

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
$segment_key).

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
shm_attach().

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?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello,

On 07/22/2004 10:58 PM, Google Mike wrote:
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?


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:

http://www.phpclasses.org/filecache
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.