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.
我正在创建一个调试模块,允许用户在主动观察页面变化时进行单行ajax调用。问题是用户是否正在尝试进行数据库调用。
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.
用户可以运行mysql_connect()函数,但是一旦ajax调用完成,该连接立即关闭。有没有办法保持连接开放?我看过mysql_pconnect(),但这似乎没有做我想要的。
Thanks
谢谢
3 个解决方案
#1
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.
我必须迷路。脚本运行后,连接应该关闭,gc应该在服务器上清理它。否则,你会遇到一些内存问题。
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.
此外,Ajax调用不应该建立任何数据库连接,而应该是服务器上运行的脚本。同样,该脚本应在完成后关闭连接。
I guess I don't really understand the problem you're having.
我想我真的不明白你遇到的问题。
#2
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.
如果你真的需要保持连接打开,我会考虑设置你从mysql_connect()获得的任何返回值作为用户会话值(免责声明:我不知道PHP,这是我假设你使用的)。然后每个AJAX请求测试它的存在和重用(如果已经存在)。但是,如果你面临的真正问题是维持某种特定于连接的瞬态状态,我会重新考虑设计并在与用户会话中的某种唯一标识符相关联的连接之间执行某些操作。
#3
0
Run your script in fast-cgi mode as a single process. Or even use something like http://phpdaemon.net
以fast-cgi模式运行脚本作为单个进程。甚至使用像http://phpdaemon.net这样的东西
#1
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.
我必须迷路。脚本运行后,连接应该关闭,gc应该在服务器上清理它。否则,你会遇到一些内存问题。
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.
此外,Ajax调用不应该建立任何数据库连接,而应该是服务器上运行的脚本。同样,该脚本应在完成后关闭连接。
I guess I don't really understand the problem you're having.
我想我真的不明白你遇到的问题。
#2
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.
如果你真的需要保持连接打开,我会考虑设置你从mysql_connect()获得的任何返回值作为用户会话值(免责声明:我不知道PHP,这是我假设你使用的)。然后每个AJAX请求测试它的存在和重用(如果已经存在)。但是,如果你面临的真正问题是维持某种特定于连接的瞬态状态,我会重新考虑设计并在与用户会话中的某种唯一标识符相关联的连接之间执行某些操作。
#3
0
Run your script in fast-cgi mode as a single process. Or even use something like http://phpdaemon.net
以fast-cgi模式运行脚本作为单个进程。甚至使用像http://phpdaemon.net这样的东西