0

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 closes 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

jwegner
  • 7,043
  • 8
  • 34
  • 56
  • 2
    What's the point of keeping the database connection open? – Richard Marskell - Drackir Nov 16 '10 at 19:59
  • 1
    If you want to reduce/kill scalability by making sure all connections are tied up, go ahead. – Oded Nov 16 '10 at 20:05
  • If you had really read my post, you would have noticed that this is a debugging module. The entire point of this project is to help in designing a page - IE: When there are no other users connected. Scalability is pointless, when you are running on localhost. – jwegner Nov 16 '10 at 20:49
  • Is mysql_connect() PHP specific? If so, might want to retag your question. – orangepips Nov 16 '10 at 21:57

3 Answers3

0

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.

  • You are exactly correct. The script runs, and then the connections closes and cleans up. This is what I want to stop. I want the user to call an ajax script that connects to the database, then that script ends. Then the user calls another script that pulls data from the database - but I need them to pull this data using the same connection they created in the first script. Essentially, I need a database connection that is persistent throughout the user's session. – jwegner Nov 16 '10 at 20:46
0

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.

orangepips
  • 9,891
  • 6
  • 33
  • 57
0

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

Qwerty
  • 1,732
  • 1
  • 13
  • 18