简体   繁体   中英

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. 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.

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?

Use MySQL as much as possible in this situation. 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.

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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