PHP+AJAX with MySQL - Query every 2 seconds, too many in TIME_WAIT

Posted by Ryan on Server Fault See other posts from Server Fault or by Ryan
Published on 2010-12-08T22:39:26Z Indexed on 2012/11/24 17:06 UTC
Read the original article Hit count: 345

Filed under:
|
|
|

I have a basic HTML file, using jQuery's ajax, that is connecting to my polling.php script every 2 seconds.

The polling.php simply connections to mysql, checks for ID's newer than my hidden, stored current ID, and then echo's if there is anything new. Since the javascript is connecting every 2 seconds, I am getting thousands of connections in TIME_WAIT, just for my client. This is because my script is re-connecting to MySQL over and over again. I have tried mysql_pconnect but it didn't help any.

Is there any way I can get PHP to open 1 connection, and continue to query using it? Instead of reconnecting every single time and making all these TIME_WAIT connections. Unsure what to do here to make this work properly.

© Server Fault or respective owner

Related posts about mysql

Related posts about php