Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
mysql not reusing a connection Ver 14.14 Distrib 5.7.29, for Linux (x86_64)
[Ubuntu]: 18.04.4 LTS
[Apache]: Apache/2.4.29 (Ubuntu)
[MySQL]: Ver 14.14 Distrib 5.7.29, for Linux (x86_64) 
[PHP]: 7.2.24-0ubuntu0.18.04.3 (cli) 

MySQL Does Not Reuse Exisitng Connection.

SELECT * 
FROM INFORMATION_SCHEMA.PROCESSLIST 
WHERE DB="mySchema" and state <>"executing" order by id;    

Upto 10 Connections are created. Once these connections are created, the connections begin to be reused and the TIME column is reset . Surely 1 connection should be created and reused.

Replicated on GCloud LAMP Install and Local Machine LAMP Install. Not able to replicate on Local Machine WAMP Install.

To replicate:

  1. Create a PHP script to connect to a MYSQL table, for example the one below.
  2. Run the script 10 times, wait for 10 seconds between each execution.
  3. Note that upto 10 connections are created. 4 .Note that once these connections are created, the connection is reused, and the TIME column is reset.

my code:

<?php
$options = [
PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT=>true
];
$conn = new PDO("mysql:host=localhost;dbname=mySchema", "myUser", "myPassword", $options);
$stmt = $conn->query("SELECT * FROM myTable;");
$row=$stmt->fetch(PDO::FETCH_NUM);
$conn = null;
?>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Removed the default database from the DSN. This ensures the 10 connections can be reused across the multiple schemas in the CRUD application.

over 4 years ago · Santiago Trujillo Relatório

0

Surely 1 connection should be created and reused

Surely? Nothing in the data you provide in your question points at any reuse of connections.

If there is a connection pool, it will make sure that eventually connections are reused, but there's no guarantee that the same connection will be used over and over and over until a second one is required concurrently. I'm assuming that your environment behaves correctly based on its (undisclosed) configuration.

As you say you can replicate this on one environment, but not on another: That points to different configurations, not at any wrong behavior.

And it doesn't look like anything you need to worry about.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda