简体   繁体   English

使用php / mysql实时搜索防止多个同时查询

[英]preventing multiple simultaneous queries with php/mysql live search

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. 但是,如果用户输入的速度比返回结果的速度快,那么它经常遇到服务器上的许多版本的搜索查询同时运行的问题。

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. 我正在中止一个新的ajax请求,但这当然不会影响服务器上已经处理的查询,并且你最终会遇到严重的瓶颈和漫长的等待以获得最终结果。 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. 我正在使用带有MyISAM表的MySQL,并且在转换为InnoDB时似乎没有任何优势,因为结果集将是理智的行。

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. 我尝试使用会话变量使PHP等待,如果此会话已经有一个正在进行的查询但似乎停止它完全工作。

The problem is solved if I make the ajax requests syncrhonous, but that would rather defeat the object here. 如果我使ajax请求同步,问题就解决了,但是这样会在这里击败对象。

I was wondering if anyone had any suggestions as to how to make this work properly. 我想知道是否有人有任何关于如何使这项工作正常的建议。

Best regards John 最好的问候约翰

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)? 在做更复杂的事情之前,您是否考虑过在用户停止输入至少一定时间间隔(比如1秒)之前不发送请求? That should dramatically cut the number of requests being made with little effort on your part. 这应该会大大减少您的请求数量而不需要您付出太多努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM