开发者

Keep database connection open through ajax calls

开发者 https://www.devze.com 2023-01-25 04:26 出处:网络
I\'m creating a debugging module that will allow the user to make single-line ajax calls while they are actively watching how the page changes.The problem is if the user is trying to make database cal

I'm creating a debugging module that will allow the user to make single-line ajax calls while they are actively watching how the page changes. The problem is if the user is trying to make database calls.

The user can run the function mysql_connect(), but then that connection immediately close开发者_如何转开发s once the ajax call completes. Is there a way to keep that connection open? I've looked at mysql_pconnect(), but that doesn't seem to do what I want.

Thanks


I must be lost. Once the script runs, the connection should close and the gc should clean it up on the server. Otherwise, you'll have some memory issues.

Also, the Ajax call shouldn't be making any database connection, but rather the script running on the server should. Again, that script should close the connection once it finishes.

I guess I don't really understand the problem you're having.


If you really need to keep the connection open I would consider setting whatever return value you're getting from the mysql_connect() as a user session value (disclaimer: I don't know PHP, which is what I assume your using). Then with each AJAX request test for its existence and reuse if already present. However, if the real issue your facing is maintaining some sort of transient state specific to the connection I would reconsider the design and do something that persists between connections tied to some sort of unique identifier from the user's session.


Run your script in fast-cgi mode as a single process. Or even use something like http://phpdaemon.net

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号