I deduce numbers in ModX Revo (inserted in the bottom of the template):

MySQL: [^qt^], [^q^] request(s), PHP: [^p^], total: [^t^], document from [^s^] 

Snippet code - 1 variant (output 32 lines of 5 cells from the database):

 $query = $modx->query($sql); while ($i= $query->fetch(PDO::FETCH_ASSOC)) {блабла} 

Watching the numbers:

MySQL: 0.4114 s, 32 request (s), PHP: 0.1472 s, total: 0.5586 s, document from database

MySQL: 0.3293 s, 3 request (s), PHP: 0.0904 s, total: 0.4197 s, document from cache

Snippet code - option 2 :

 $query = $modx->prepare($sql); $query->execute(); while ($i= $query->fetch(PDO::FETCH_ASSOC)) {блабла} 

Watching the numbers:

MySQL: 0.0098 s, 31 request (s), PHP: 0.5625 s, total: 0.5722 s, document from database
MySQL: 0.0005 s, 2 request (s), PHP: 0.4296 s, total: 0.4301 s, document from cache

How so? The total time of the formation of the page is essentially the same, but variations in the components .. What is the way to choose?

UPD.
Version of ModX Revo.
Output from custom table.
Query: SELECT text, link FROM custom_table WHERE order_id>0
What for? The site has a high attendance, this request should be implemented for each visitor, the cache is not possible, since the data in the table is updated every 5-10 minutes. Do cash for 10 minutes? Perhaps))) That is, with a large load, something will be more subtle or PHP or MySQL.

  • one
    In the second, do you use some tricky output via $ modx-> getChunk? - Vasis
  • in the sense of? snippet is inserted into the template, snippet code at the top is shown ... in echo loop $ i ['fields_name'] - Sergey V.
  • Snippet is called directly in the template, chunks are not involved in any way at all - Sergey V.
  • one
    You did not specify any additional information - not for the version of the modiks, or why you need it. What are these tables, what data ... - Vasis
  • updated the question ... - Sergey V.

1 answer 1

Judging by the general page timing, different times for executing a query are just some kind of measurement defect, and not an actual difference. The code consisting of prepare and execute does exactly the same thing as a simple query call (unless, of course, the prepared expression is reused, which is not the case in this example).