且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP中的请求之间存储对象而不进行序列化

更新时间:2022-06-25 05:07:57

每当您需要存储(冻结)对象时,都需要对其进行序列化.这与存储(APC,会话文件,数据库等)无关,这是因为脚本进程将终止,并且下次启动时,对象需要重新恢复生命.

Whenever you need to store (freeze) an object, it needs to be serialized. That's independent to the storage (APC, session files, database etc.), it's because the script process will terminate and next time it starts, the objects need to come to life again.

因此无法将事物保持在运行状态",对象将始终被序列化存储.

So things can not be kept in a "run-state", objects will always be serialized to be stored.

众所周知,PHP序列化不是最快的.您可以使用其他替代实现,例如 igbinary PHP扩展 .它在透明会话处理旁边提供了序列化/反序列化功能.也许这实际上对您的情况很有帮助.

It's known that PHP serialization is not the fastest. There are alternative implementations to it, you can use, for example igbinary PHP extension. It offers a serialize /deserialize function next to transparent session handling. Maybe this is actually helpful for your scenario.

在任何情况下:您在会话中存储的内容越多,在请求开始时需要解冻或唤醒的时间越长,花费的时间就越多.

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

相关:什么是php_binary序列化处理程序?