mysql - Connect to database for heavy traffic website Mysqli and PHP -


while coding use default connecting config is:

//connection information define('database_user', 'root'); define('database_password', '*********'); define('database_host', 'localhost'); define('database_name', 'mydatabase');  // override default php.ini settings sending mail date_default_timezone_set("america/indianapolis");   //connecting $con = mysqli_connect(database_host, database_user, database_password,database_name);  if (!$con) {      trigger_error('could not connect mysql: ' . mysqli_connect_error());     } 

but normal connection website, if have heavy traffic website facebook or other websites using mysql database side, have users, comments, changing data every second. same way or there better way avoid

max_use_connections

warning other website going slow in first use normal later going slow day after day till restart server.

i tried other solutions using different database everyday, don't think solution because looking keep data in 1 database searching side.


for counting using query as:

mysqli_query($con, "select * `table` `id` = '$user_id'"); 

for selecting , getting data use:

$table = mysqli_query($con, "select * `table` `id` = '$user_id'");  if(mysqli_num_rows($table) !== 0)    {       while($rows = mysqli_fetch_array($table))          {                $id = $rows['id'];                ......          }    } 

for live update have every second new change , data using ajax. every ajax call open new connection? , have close every connection after getting data , why?

is same way

yes.

is every ajax call open new connection?

yes.

do have close every connection after getting data , why?

no. php close you.

i appreciate time , information let me more knowledgeable avoid as can wrong way while coding :)

all coding wrong , years be. learn , in time you'll able ho create site can sustain traffic 1/1000000th of facebook.

however, it's impossible put years of heavy learning few paragraphs of regular answer. hope understand.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -