Data persistence
In this context, data persistence is taken to mean any data that is intended to survive the current request. The memory management within the engine is very focused on request bound allocations, but this is not always practical or appropriate. Persistent memory is sometimes required in order to satisfy requirements of external libraries, it can also be useful while Hacking
.
A common use of persistent memory is to enable persistent SQL server connections, though this practice is frowned upon, it is none the less the most common use of this feature.
Note: All of the following functions take the additional persistent parameter, should this be false, the engine will use its regular allocators (emalloc) and the memory should not be considered persistent. Where memory is allocated as persistent, system allocators are invoked, under most circumstances they are still not able to return NULL pointers just as the Main memory APIs.
Prototype | Description |
---|---|
void *pemalloc(size_t size, zend_bool persistent) |
Allocate size bytes of memory. |
void *pecalloc(size_t nmemb, size_t size, zend_bool persistent) |
Allocate a buffer for nmemb elements of
size bytes and makes sure it is initialized with zeros.
|
void *perealloc(void *ptr, size_t size, zend_bool persistent) |
Resize the buffer ptr , which was allocated using
emalloc to hold size bytes of memory.
|
void pefree(void *ptr, zend_bool persistent) |
Free the buffer pointed by ptr . The buffer had to be
allocated by pemalloc .
|
void *safe_pemalloc(size_t nmemb, size_t size, size_t offset, zend_bool persistent)
|
Allocate a buffer for holding nmemb blocks of each
size bytes and an additional offset bytes.
This is similar to pemalloc(nmemb * size + offset) but adds
a special protection against overflows.
|
char *pestrdup(const char *s, zend_bool persistent) |
Allocate a buffer that can hold the NULL-terminated string
s and copy the s into that buffer.
|
char *pestrndup(const char *s, unsigned int length, zend_bool persistent)
|
Similar to pestrdup while the length of the
NULL-terminated string is already known.
|
It is important to remember that memory allocated to be persistent is not optimized or tracked by the engine; it is not subject to memory_limit, additionally, all variables that are created by the Hacker
for the engine must not use persistent memory.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-internals2.memory.persistence.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.