PHP shmop how to store an array in shared memory

I need to store about 6-8 GB of static data in shared memory as an ARRAY OBJECT object. Data is retrieved from the database. I want fork () and allow children to access and search for elements in an index based array.

As far as I can tell, I can store the "strings" using shmop (). But I want to save an array that PHP recognizes as an array object.

Any suggestions?

+4
source share
4 answers

shmop can really store strings. To save an array, you will need to serialize it before you save it and unserialize it before using it.

0
source

You can always serialize an ArrayObject and use Memcached to store it in memory.

If you want to stick with shmop: since shmop_write() uses strings to store data, you also need to use the serialize() method.

0
source

Use the PHP function serialize() .

http://php.net/manual/en/function.serialize.php

I would recommend writing a class that takes care of serialization / deserialization and writing / reading into shared memory.

0
source

It looks like this could be performed by the PHP SEM function .

It serializes the objects inside. Given the sheer amount of data, performance increases significantly with data volume. And 8GB (and boost) is too much for shmop and SEM for efficient processing.

My alternative is to simply query the database if necessary (while maintaining the local cached version for each thread), which, in my opinion, will turn out to be faster (especially with SSDs). Therefore, these functions do not suit me.

0
source

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


All Articles