What can I use for fast temporary storage in PHP?

I am creating a small plugin that processes some images. Now, to report the progress to the user, I have a small ajax script that will check the results for a long time.

Now I need an object that keeps track of what is being processed. Now the options that I know of are as follows.

Using a PHP session object. I cannot use this in this particular case, because the initial process also runs ajax. So the main process is the ajax call, and the long ajax polling is another ajax call. They have two different session identifiers, so they do not communicate well.

The second option is to use the database as a repository. I donโ€™t know if this is good, because the average job will have about 40 read / write operations. I know this is not a problem, but it seems a little big for something so simple.

What I'm really looking for is a kind of memory object, if possible. Create a small object in memory that updates quickly with the move and is deleted when we are done.

I don't know if this is possible, such a thing exists in PHP, and I can use it. Please note that this will be a public plugin, so I need to work with methods that are available for all types of systems, nothing special.

+6
source share
5 answers

I think this is not the worst solution. If you are thinking of writing to a disc, maybe it could be worse.

Memcache is good, but you need a small plug-in "external plugins" that runs easily on win, linux, mac, etc .... this is not a good option.

If you use Mysql, you can use the memory engine tables, quickly and crop it or periodically clean it using a simple garbage collection algorithm. And if the memory table is not an option, innodb is good enough.

+5
source

Check out Redis , โ€œan open source, advanced keystore,โ€ I think you'll like it.

You need to start the Redis server and access it using clients . The client of choice for PHP is Predis . Using is very simple:

$client = new Predis\Client($single_server); $client->set('library', 'predis'); $retval = $client->get('library'); 
+1
source

You can use memcache for this. http://php.net/manual/en/book.memcache.php As a key, you can use the hash file md5 of the image file and ip users.

+1
source

A database is a good idea when you use a heap table. Sometimes you just donโ€™t have memcache on the server.
Check Memory Tables in MySQL documentation

+1
source

Do you need simple, portable, shared memory between php processes, no matter how php is installed? use mysql memory table. php without mysql installed is pretty rare.

+1
source

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


All Articles