According to the code, you need to connect every time.
But there are a couple of moments:
1) Worked on the application where, after rebooting the database, it was necessary to overload php-fpm / lighttpd ( lighttpd / php5-fpm / pdo / postgres ). Those. It looks like it was either cached or not closed.
2) Functions with probable connections exist. http://php.net/manual/en/features.persistent-connections.php
The essence of PHP is that it quickly worked and forgotten. Therefore, in fact, it is not a problem to open for each access to the server connection to the database. The main thing is not to open the connection for each request that you execute in the script. And what would the script / query run quickly.
And if you want to optimize:
- Optimize requests (
explain in help). - See caching
memcahced , redis ...