使用 PHP/KohanaPHP 自动建议和快速响应 + MySQL + jQuery
我需要知道如何以最佳方式执行此操作,以便建议能够快速且安全地加载。我想要一些类似相关问题在输入问题标题后如何工作的信息。
I need to know how to execute this in the best way possible so that the suggestions will load really quick and secured. I want something like how the Related Questions work here after typing a question title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想 jQueryUI 将使用新的 Autocomplete 小部件来完成这项工作。
然而,响应时间与服务器响应时间(你的php脚本执行时间、服务器连接)和客户端(用户连接)有关。
I guess jQueryUI will make the job with the new Autocomplete widget.
However, the response time is related to both server response time (your php script execution time, server connection) and client side (user connection).
我在 Kohana 之上完成了一些 jQuery 编码,重要提示是您不想发出太多请求。例如,不要每次添加字母时都调用服务器,而仅在用户停止书写或按空格等时调用服务器。
当您想到它时,尝试过于频繁地发送似乎会给出更快的响应,但浏览器限制了数量Ajax 的连接数。如果此时有多个 Ajax 查询正在进行,某些 IE 会等待发送请求。
剩下的只是在服务器上加快速度;)
在一个 MySQL 查询中获取所有内容。
警告:如果查询在大型表上进行一些连接,您可能需要重新设计...或者执行单独的查询并使用 PHP 构建它。连接大表总是很慢。而且你通常并不真正需要它:)
I've done some jQuery coding on top of Kohana and the important tip is that you don't want to make too many requests. E.g. don't call the server every time a letter is added, but only when user stops writing or presses space, etc.
Trying to send it too often seems to give a faster response when you think of it, but browsers have limited a number of connections for Ajax. Some IEs wait with sending requests if there is more than one Ajax query being made at the moment.
The rest is just making it quick on the server ;)
Fetch everything in one MySQL query.
Caution: If the query does some joins on large tables you probably need to redesign... Or do separate queries and build it up with PHP. Joining large tables is always slow. And you most often don't really need it :)