Persistent MySQL Query Results with PHP

Is there a way to store the query results using PHP so you can use it in another call to the webserver?

I know there is no way to store the resource in php but looking for an alternative way to do this:

I have a report server and some queries take a few seconds and return 10,000 records (might be 10MB in size). I would like to be able to use the mysqli_stmt :: data_seek resource to view the results when the user requests a new page instead of a query each time and uses constraints and offsets

Is there any technology that would allow me to do this?

some thoughts would be to put the php socket server inbetween to request a request through the socket server, which can keep the resource up for 5 minutes for additional page requests. if the resource is no longer available it will run the query with limit and offset

any ideas or other thoughts would be much appreciated!


source to share

3 answers

Do you want to look at memcached

PHP has an interface for this.



If you've serialized your data, you can use APC or Memcached to store an object / array containing your data. Memcached will require an actual memcached server to be running on your server along with the memcached extension installed, while APC requires nothing but an extension.



You can also look into PHP's shared memory usage .

The nice thing is that it allows you to store strings, so you'll have to serialize your data. Not sure how this will affect performance, but at least you will be writing and reading from RAM, which is always fast.

Another disadvantage is that, as with every memory operation, you need to specify how many bytes you want to reserve in advance, but not dynamically like Memcache.

Perhaps you might initially reserve much more than you need (e.g. 20 MB instead of 10 MB) and store the size of the data currently stored in the first 8 bytes. For example. if your data was 123456 bytes, you can store the serialized data as "00123456 {serialized data}" and then read it by specifying an offset:

$size = (int) shmop_read($shmid, 0, 8);
shmop_read($shmid, 8, $size);


Another thing to remember is only working with Windows, but this shouldn't be a problem if you have a decent backend server :)



All Articles