Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a shared object between different sessions in PHP?

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?

like image 374
jondinham Avatar asked Oct 09 '22 11:10

jondinham


1 Answers

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.

like image 151
hakre Avatar answered Oct 13 '22 10:10

hakre