4

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

As far as I'm concerned I can only store "strings" using shmop(). But I want to store an array that PHP recognizes as an array object.

Any suggestions?

4 Answers 4

1

It appears this can be accomplished by PHP's SEM functions.

It serializes the objects internally. Given the sheer amount of data, performance decreases tremendously with increasing data. And 8GB (and rising) is too much for shmop and SEM to handle efficiently.

My alternative is to simply query the database when needed (while storing a local cached version for each thread), which I think would prove to be faster (especially with SSD). So these functions are not the way for me to go.

Sign up to request clarification or add additional context in comments.

Comments

0

shmop can only really store strings. To store an array, you'd need to serialize it before you store it and unserialize it before using it.

Comments

0

You could always serialize the 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'll need to use the serialize() method there too.

Comments

0

Use PHP's serialize() function.

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

I would recommend writing a class that takes care of serializing/deserializing and writing/reading to the shared memory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.