views:

12

answers:

1

Hi, My php script waits for remote gate response, normally for ~20 seconds. It causes apache httpd threads to live in memory with opened MySQL connection and finally to exceed MaxClients value. How it can be managed to free idle resources until remote gate reponse.

One solution is: 1) run remote gate request and then redirect user to page that refreshes to certain url testing for data coming, 2) write rule for that url in nginx configuration file: if specific file exist then run apache to give data else show refreshing page. 3) remote gate request saves data in file

Therefore we unlinked apache from the script that makes request to remote gate and we can make it tiny as possible. While remote request, server used only by that script and light requests from nginx.

So it may be good solution, but I would like to know downsides of this approach. And may be there are better ways.

A: 

Well, you could close your MySQL-connection while waiting for the remote gates response.

mysql_close($link);

And then reopen it once you got the response:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

If you need the MySQL connection only before or only after the remote gate response, I would suggest establishing the MySQL connection only once at the correct possition.

In general mysql_connect() is a little expensive. But compared to the 20sec your response needs, this is definitely inexpensive.

JochenJung