简体   繁体   中英

MySQL Too many connections on REST API server (PHP Yii2)

Looking for advice here on how I could better structure my application. I have a REST API that is used by mobile apps. The API is built in PHP using the Yii2 framework which uses ActiveRecord (a DAO model class) for accessing all the data in the database.

Most of the time the API works fine but occasionally there is a spike in API requests and by extent a spike in the DB connections which means that all responses start returning a "Too many connections" error. I can imagine that there's some flaw in the mobile apps that's causing an app to send through too many requests in a loop but as my application scales I'm wondering if there's someway to manage this on the server side (rather than always relying on the mobile app developers to write efficient code). Any advice welcome here and open to migrating the API to another framework if it means that it will scale better.

You can configure mysql to increase the maximum. You shouldn't need more than the total number of PHP processes you are running. If you are running your API off a single server, I'd imagine you only need a couple of hundred connections, but multiply that by the number of application services.

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