I am creating a small plugin that process some images. Now to report the progress back to the user I have a small ajax script that will long poll the results back.
Now intern I need an object that keeps track of what is processed. Now the options I am aware of are the following.
Using the PHP session object. I cannot use this in this specific case, because the initial process is also done by ajax. So the main process is a ajax call, and the long poll ajax is another ajax call. They have 2 different session id’s, so they do not communicate well.
Second option is to use the database as the storage. I do not know if this is so good because there will be around 40 read / writes on an average job. I know that this is no problem, but it seems a little much for something so simple.
What I actual look for is a sort of memory object if that is possible. Create a small object in the memory that is rapidly updated with the progress and deleted when we are done.
I do not know if that is possible, exists such a thing in PHP, and can I make use of this. Note that this will be a public plugin, so I need to work with methods that are available on all kind of systems, nothing special.
I think database is not the worse solution. If you think write in disk, maybe can be worse.
Memcache is good, but you need a “external plugins free” small plugin who runs easily on win, linux, mac, and so on… is not a good option.
If you use Mysql, you can use Memory engine tables, witch is fast, and truncate it or clean it periodically, with a simple garbage collector algoritm. And if memory table is not a option, innodb is good enough.