Page 1 of 1
PHP Extensions - Persistent Memory
Posted: Wed Sep 15, 2010 3:24 pm
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
Re: PHP Extensions - Persistent Memory
Posted: Wed Sep 15, 2010 5:46 pm
by Jonah Bron
What kind of extension? Can you use sessions instead?
Re: PHP Extensions - Persistent Memory
Posted: Wed Sep 15, 2010 7:23 pm
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.
Re: PHP Extensions - Persistent Memory
Posted: Wed Sep 15, 2010 7:45 pm
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