PHP Azure App Service SNAT Port Exhaustion when connected to an Azure mySQL DB

Michelle Blum 821 Reputation points Microsoft Employee Moderator
2020-12-23T19:13:08.747+00:00

I am seeing SNAT Port exhaustion when connecting to an Azure mySQL DB from my PHP Azure App Service. It is my understanding that if my destination is an Azure service that supports service endpoints, you can avoid SNAT port exhaustion issues by using regional VNet Integration and service endpoints or private endpoints. Before I consider using regional Vnet integration is there anything else I can try?

Troubleshooting intermittent outbound connection errors in Azure App Service

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,963 questions
0 comments No comments
{count} votes

Accepted answer
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2020-12-24T18:01:49.277+00:00

    PHP connects to SQL Server (including Azure SQL) using PDO (PHP Data Objects). By design, it does not support Connection pooling. Instead, it has a feature called Persistent Database Connections.

    To use the feature, you must connect to DB like this:

    51037-image.png

    As demonstrated in above example, the value of PDO::ATTR_PERSISTENT in the driver options array needs to be set as true in the PDO constructor. It will not work if you try to set the attribute using PDO:: setAttribute() after instantiation of PDO object. For more info, check the document here.

    In case of MySQL, we have the option of using Persistent connections while using MySQLi driver.

    If a unused persistent connection for a given combination of host, username, password, socket, port and default database cannot be found in the connection pool, then mysqli opens a new connection. The use of persistent connections can be enabled and disabled using the PHP directive mysqli.allow_persistent. The total number of connections opened by a script can be limited with mysqli.max_links. The maximum number of persistent connections per PHP process can be restricted with mysqli.max_persistent. Please note, that the web server may spawn many PHP processes.

    Note: mysql_pconnect extension has been removed from PHP 7.0, and hence is no longer an alternative solution for opening persistent connections.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.