PHP Extensions - Persistent Memory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pmarq
Forum Newbie
Posts: 1
Joined: Wed Sep 15, 2010 3:18 pm

PHP Extensions - Persistent Memory

Post by pmarq »

I'm writing a custom extension in php and I'm storing some values in persistent memory using pemalloc and zend_hash_add functions. When I retrieve the stored values in a separate request they are loaded properly, but if I wait about 5 seconds after the last request and refresh again, the values are no longer there.

Is it possible that there's some kind of configuration setting in php that controls the length of time a value can be stored in persistent memory before it's destroyed?

Any help would be appreciated.

-Phil
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Extensions - Persistent Memory

Post by Jonah Bron »

What kind of extension? Can you use sessions instead?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Extensions - Persistent Memory

Post by Weirdan »

pmarq wrote:I'm writing a custom extension in php and I'm storing some values in persistent memory using pemalloc and zend_hash_add functions. When I retrieve the stored values in a separate request they are loaded properly, but if I wait about 5 seconds after the last request and refresh again, the values are no longer there.
I'm not a C expert, however it seems to me that the issue you see stems from the fact your final request is served by a different process then what was used for previous requests (due to the multiprocess webserver design like Apache's prefork). Multiple processes, naturally, don't share the address space, so memory you allocated and written in process A is not available in the process B. By the way, what webserver you use and, if it's Apache, what MPM it uses? If my assumption is correct and you, in fact, want to share some data across a process pool, then you're using wrong tool for the job. What you need (as I undestood it) is shared memory storage like what is used by APC and similar extensions.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Extensions - Persistent Memory

Post by Eran »

Consider using the shared memory extension, though it will create a dependency
http://php.net/manual/en/book.shmop.php
At the very least, you can look at the source code to see how it's done there
Post Reply