Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent database connection for Ajax Calls

I have ajax call which pulls from the processing script 'getajax.php'.

Call is made to 'getajax.php' script which has the db connection details, select, functions, etc.

My question is:

Everytime a call is received by 'getajax.php' it will go through mysql_connect, mysql_select, then queries.

Is this the correct aproach to handle thousands of simultaneous calls?

How can I avoid mysql connection to be opened everytime a call is made, reusing one existing connection for all calls.

Trying to have one call to:

$dbconnect = mysql_connect('host','user','pass');
mysql_select_db('databasename') or die( "Unable to select database");

How can I open a persistent connection on parent so 'getajax.php' script just reususes this connection without running these mysql commands over and over.

Unsure how to aproach.

Thanks All!

like image 699
Codex73 Avatar asked Oct 26 '22 07:10

Codex73


1 Answers

You can use mysql_pconnect (http://www.php.net/manual/en/function.mysql-pconnect.php) which creates a persistent connection to the database.

like image 140
halfdan Avatar answered Nov 15 '22 05:11

halfdan