How to create a shared object between different sessions in PHP?
I'm thinking of using file or MySQL memory table. Using file isn't a good option because it doesn't have locking and is slow. Using MySQL memory table is a good option, but how to save class instances (objects) to a table? Serializing an object and put it to table is also slow.
Option 1: MySQL memory table
Option 2: shm_attach,shm_detach,shm_get_var,shm_has_var,shm_put_var,..
Option 3: Memcache
The problem is using MySQL memory table requires querying. Memcache is not included in standard PHP installation. To have shm_* functions on Windows, it's required to get PHP built from source with option "--enable-sysvsem", and this requires setting in php.ini where developer may not be able to access all the time.
Which one of the above is the better? Any other options?
If you want to share objects (instances of classes) between different processes, you will always be bound to serialize
and unserialize
regardless which kind of storage layer you use (database, memchace, files, ...).
If you don't want to use serialize
and unserialize
, then there is not much that you can do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With