持久MySQL查询结果w/ PHP

时间:2023-01-15 03:45:31

Is there any way to persist the query results using PHP so you can use it another call to the web server?

有什么方法可以使用PHP来持久化查询结果,以便您可以对web服务器进行另一个调用吗?

i know there is no way to persist a resource in php but looking for an alternative way to accomplish this:

我知道用php保存资源是不可能的,但是要找到一种替代方法来实现这一点:

i have a reporting server and some queries will take several seconds and return 10,000's of records (could be 10's of MB in size). i would like to be able to use the resource mysqli_stmt::data_seek to page through the results when the user requests a new page instead of requering each time and using limit & offsets

我有一个报告服务器,一些查询需要几秒钟的时间并返回10,000条记录(大小可能是10 MB)。我希望能够使用资源sqmyli_stmt:data_seek在用户请求新页面时浏览结果,而不是每次都请求,并使用limit &偏移量

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

有什么技术可以让我这么做吗?

some thoughts would be to put a php socket server inbetween request the query through the socket server which can keep the resource alive for say 5 minutes for additional page requests. if the resource is no longer available it will then run the query w/ a limit & offset

有些想法是将php套接字服务器插入到通过套接字服务器请求查询的中间,这可以使资源在5分钟内保持活力,以便进行更多的页面请求。如果资源不再可用,那么它将运行查询w/ a limit & offset

any ideas or other thoughts would be greatly appreciated!

任何想法或其他想法都将非常感谢!

3 个解决方案

#1


1  

You'll want to look into memcached

您需要查看memcached

PHP has an interface for it.

PHP有一个接口。

#2


1  

If you serialized your data you could use APC or Memcached to persist an object / array that contains your data. Memcached would require that your server runs the actual memcached server along with having the memcached extension installed, while APC doesn't require anything special besides the extension.

如果序列化了数据,可以使用APC或缓存的memto持久化包含数据的对象/数组。Memcached要求服务器运行实际的Memcached服务器,并安装Memcached扩展,而APC除了扩展之外不需要任何特殊的东西。

#3


1  

You could also look into using PHP's shared memory.

您还可以研究如何使用PHP的共享内存。

One bad thing about is that it only allows you to save strings so you would have to serialize your data. Not sure how that would impact the performance but at least you'd be writing to and reading from RAM, which is always fast.

其中的一个缺点是,它只允许保存字符串,因此必须序列化数据。不知道这会如何影响性能,但至少你会在RAM中读写,这总是很快的。

Another drawback is that as with every memory operation you need to specify how many bytes you want to reserve in advance, it's not dynamic like Memcache.

另一个缺点是,对于每个内存操作,您需要预先指定要保留的字节数,它不像Memcache那样是动态的。

You could probably initially reserve much more than you need (e.g. 20MB instead of 10MB) and store the size of the currently stored data in the first 8 or so bytes. E.g. if your data was 123456 bytes long you could store the serialized data as "00123456{serialized data}" and then read it by defining the offset:

您可能会首先保留比您需要的更多的东西(例如20MB而不是10MB),并存储当前存储在前8个字节中的数据的大小。如果您的数据是123456字节,那么您可以将序列化数据存储为“00123456{序列化数据}”,然后通过定义偏移量来读取它:

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

Another thing to remember is it only works on Windows but it shouldn't be a problem if you have a decent server backend :)

另一件需要记住的事情是,它只在Windows上工作,但如果您有一个像样的服务器后端,它应该不会成为问题:)

#1


1  

You'll want to look into memcached

您需要查看memcached

PHP has an interface for it.

PHP有一个接口。

#2


1  

If you serialized your data you could use APC or Memcached to persist an object / array that contains your data. Memcached would require that your server runs the actual memcached server along with having the memcached extension installed, while APC doesn't require anything special besides the extension.

如果序列化了数据,可以使用APC或缓存的memto持久化包含数据的对象/数组。Memcached要求服务器运行实际的Memcached服务器,并安装Memcached扩展,而APC除了扩展之外不需要任何特殊的东西。

#3


1  

You could also look into using PHP's shared memory.

您还可以研究如何使用PHP的共享内存。

One bad thing about is that it only allows you to save strings so you would have to serialize your data. Not sure how that would impact the performance but at least you'd be writing to and reading from RAM, which is always fast.

其中的一个缺点是,它只允许保存字符串,因此必须序列化数据。不知道这会如何影响性能,但至少你会在RAM中读写,这总是很快的。

Another drawback is that as with every memory operation you need to specify how many bytes you want to reserve in advance, it's not dynamic like Memcache.

另一个缺点是,对于每个内存操作,您需要预先指定要保留的字节数,它不像Memcache那样是动态的。

You could probably initially reserve much more than you need (e.g. 20MB instead of 10MB) and store the size of the currently stored data in the first 8 or so bytes. E.g. if your data was 123456 bytes long you could store the serialized data as "00123456{serialized data}" and then read it by defining the offset:

您可能会首先保留比您需要的更多的东西(例如20MB而不是10MB),并存储当前存储在前8个字节中的数据的大小。如果您的数据是123456字节,那么您可以将序列化数据存储为“00123456{序列化数据}”,然后通过定义偏移量来读取它:

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

Another thing to remember is it only works on Windows but it shouldn't be a problem if you have a decent server backend :)

另一件需要记住的事情是,它只在Windows上工作,但如果您有一个像样的服务器后端,它应该不会成为问题:)