V
V
Vernal962017-08-17 22:00:22
PHP
Vernal96, 2017-08-17 22:00:22

Is it appropriate to continuously keep the connection to the database until the end of the rendering of the web page?

For example, a page needs to perform 10-20 (sometimes more) database queries when rendering the page. Making one large query is too tedious and inconvenient, and 10 small queries are executed very quickly if you do not disconnect from the database every time. Actually the question is whether there is an alternative or is it okay if the connection lasts for two seconds continuously?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fixid, 2017-08-17
@Vernal96

Use the pool to maintain connections with MySQL, you don't need to establish a new connection, use the old one

A
Alexey Skobkin, 2017-08-17
@skobkin

Yes.

N
Night, 2017-08-17
@maxtm

Absolutely, there's nothing wrong with that. For the database - an already open connection does not give any load from the fact that it did not close within 1 sec, 10, 1000 sec.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question