Reputation: 206
Certain pages on my site are populated via numerous ajax calls, often 20+ ajax calls running asynchronously. The problem I'm having is that each call is creating a new mysql_connection, causing me to receive the 'max_user_connections' error, which I'm told is capped off at 20. I've tried turning async off, but as the JQuery documentation states, this will often freeze up the page. I have considered turning this into 1 ajax call and letting php perform the loop, but the idea was to display each element as it becomes available (some of the data is gathered from external sources, thus the timing can vary)
Is this something that can be fixed with mysql_pconnect?
Upvotes: 0
Views: 379
Reputation: 48357
Is this something that can be fixed with mysql_pconnect?
No - you need to either:
1) increase the number of connections mysql will handle (not recommended - not a scalable solution without replication)
2) improve the speed of the ajax call handler (e.g. query tuning, database/opcode/http level caching)
3) decrease the frequency of the ajax calls - e.g. by skiping the call if the last one occurred within 500msec
Upvotes: 1
Reputation: 3827
20+ Ajax calls are a concern even in absence of MySQL issue. Browser would not make these 20 calls simultaneously since it caps max http connection (to a single domian) to 2,4 or 8.
I would combine these requests and bring number of Ajax calls down to 6 - 8. As you mentioned, rest of calls get data from external sources. Do these calls talk to MySQL as well?
In addition, these things might help:
Upvotes: 0