Storing objects between requests in PHP without serialization

I am writing a stateful web application in PHP in which the state potentially contains many objects. At this point, I save all these objects in $ _SESSION and serialize them at the end of the query. This is a bit of a pain because serializing the entire session takes a few seconds, and for non-serialization it takes even longer.

I wanted to try APC because I was hoping the objects would just be memcopied, not serialized. Alas, it seems that if I pass an apc_store($object) object, it seems to serialize it before passing it to another process. (It is said that primitive values ​​and arrays are removed without serialization, but this is not a suitable solution for me, since my session objects have many (circular) links.)

My question: Is there a known way to save objects in PHP without having to serialize them after each request? I heard rumors that this HipHop interpreter might help, but I have not found working examples on the net. Can someone tell me if this is possible in PHP?

(I know I have to write this project in Java or in another language that supports persistent instances without a TCP connection)

+2
source share
2 answers

Whenever you need to save (freeze) an object, it needs to be serialized. It does not depend on the storage (APC, session files, databases, etc.), because the script process will end, and the next time it starts, the objects will come to life again.

Thus, things cannot be stored in the "execution state"; objects will always be serialized for storage.

PHP serialization is not known to be the fastest. There are alternative implementations; you can use, for example, the igbinary PHP Extension . It offers a serialization / deserialization function along with transparent session processing. Perhaps this is really useful for your scenario.

In any case: the more you store inside the session, the more you need to defrost or wake up at the beginning of the request, the more time it will take.

Related: What is php_binary serialization handler?

+3
source

In my statefull web application, I upload most of my objects to the xml repository, which also acts as a smart xml configuration. Therefore, I do not need to serialize too many objects, but only a subset (state) of my xml file. This is still a server-side approach, but can you try to offload serialization to the client? But maybe you are serializing too many objects? And why not save the object in a file at runtime?

0
source

Source: https://habr.com/ru/post/1266668/


All Articles