防止使用php/mysql实时搜索进行多个同时查询 [英] preventing multiple simultaneous queries with php/mysql live search

查看:65
本文介绍了防止使用php/mysql实时搜索进行多个同时查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以正常运行的实时搜索系统,总体上效果很好.但是,如果用户键入的速度快于返回结果的速度,则经常会遇到服务器上许多版本的搜索查询同时运行的问题.

I have a working live search system that on the whole works very well. However it often runs into the problem that many versions of the search query on the server are running simultaneously, if users are typing faster than the results can be returned.

我正在中止一个新请求时的ajax请求,但是这当然不会影响服务器上已经在进行的查询,您最终会遇到严重的瓶颈,需要很长时间才能获得最终结果.我为此使用MySQL和MyISAM表,并且转换为InnoDB似乎没有任何优势,因为结果集将是理智的行.

I am aborting the ajax request on receoipt of a new one, but that of course does not affect the query already in process on the server, and you end up with a severe bottleneck and a long wait to get your final results. I am using MySQL with MyISAM tables for this, and there does not seem to be any advantage in converting to InnoDB as the result sets will be the sane rows.

如果此会话已经在进行查询,我尝试使用会话变量使php等待,但这似乎完全阻止了它的工作.

I tried using a session variable to make php wait if this session already has a query in progress but that seems to stop it working altogether.

如果我使ajax请求同步,那么问题就解决了,但这宁可击败这里的对象.

The problem is solved if I make the ajax requests syncrhonous, but that would rather defeat the object here.

我想知道是否有人对如何使其正常工作有任何建议.

I was wondering if anyone had any suggestions as to how to make this work properly.

最诚挚的问候约翰

推荐答案

在做更复杂的事情之前,您是否考虑过直到用户停止键入至少一定时间间隔(例如1秒)后才发送请求?这样可以大大减少您的工作量.

Before doing anything more complicated, have you considered not sending the request until the user has stopped typing for at least a certain time interval (say, 1 second)? That should dramatically cut the number of requests being made with little effort on your part.

这篇关于防止使用php/mysql实时搜索进行多个同时查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆