简体   繁体   中英

PHP pdo - to many Connections

I have an angular.js application with multiple views using PHP-PDO fetching data from a MySQL database. Additionally there is a NodeJS application fetching data every 30 sec. from the same MySQL Database.

The angular and Node app run on a Windows Server. When starting the iis, tcp connections are increasing rapidly over 100, all with the Status "TIME_WAIT".

Is there a chance to reuse connections or reduce the waiting time for completely destroying a socket connection?

Connecting for every request is painfully slow. What you want is to use persistent connections and a connection pool, that way the connections can be recycled from one request to the next. This results in fewer connections and faster response times.

More information about this is in the documentation .

$db1 = null; sets your variable to null, but it doesn't inform the db server that the connection is not longer necessary so it can free up resources.

Before setting $db1 to null, close the connect

Read over the following pages for more detail http://php.net/manual/en/function.mysql-close.php and / or http://php.net/manual/en/mysqli.close.php

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