简体   繁体   English

哪个更快:在PHP中处理数据或发出多个MySQL请求?

[英]Which is faster: process data inside PHP or make several MySQL requests?

I have some extensive data to process: a very big table in MySQL. 我要处理大量数据:MySQL中很大的表。 The processing takes place three times. 该处理进行了三次。 Right now I am doing one request to MySQL and then in PHP I run a while loop three times to extract the necessary values. 现在我正在向MySQL发出一个请求,然后在PHP中运行一次while循环3次以提取必要的值。

Is what I'm currently doing the best option, or would it use less server resources to make three separate requests to MySQL with certain filters? 我目前正在做的最好的选择,还是使用更少的服务器资源使用某些过滤器向MySQL发出三个单独的请求?

Use MySQL as much as possible in this situation. 在这种情况下,请尽可能使用MySQL。 It is potentially much quicker. 它可能会更快。

EDIT: As kindly pointed out below, it is not always better to use SQL queries over processing in PHP, and as such, the statement above may be misleading. 编辑:如下文所指出的,在PHP中使用SQL查询而不是在处理中并不总是更好,因此,以上陈述可能会产生误导。

However, from the wording of this question I had assumed he was returning a large record set from the MySQL query and using several while loops to extract only certain values from the record set. 但是,从这个问题的措辞来看,我假设他正在从MySQL查询返回一个大记录集,并使用多个while循环从记录集中仅提取某些值。 If this assumption is true then I believe it would be quicker and less consumptive of resources to perform the whole operation within the MySQL query. 如果这个假设是正确的,那么我相信在MySQL查询中执行整个操作将更快,更节省资源。

As this answer isn't very helpful to people finding this with similar problems it would be grand if the original poster could post some code to clarify the exact situation. 由于此答案对发现类似问题的人不是很有帮助,因此如果原始发布者可以张贴一些代码来阐明确切情况,那将是一个很好的选择。

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

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