php - connected to mysql table depending on time -
if server time between 1-30 second connect 1 table , if more 31-60 seconds connect table.
reason why need because im not sure if 10,000 people accessing single mysql table slow down dramatically.
my code below
<?php header('content-type: application/json'); $server = "localhost"; $username = "root1"; $password = "root1"; $database = "test"; $con = mysql_connect($server, $username, $password) or die ("could not connect: " . mysql_error()); mysql_select_db($database, $con); $sql = "select id, name post order id"; $result = mysql_query($sql) or die ("query error: " . mysql_error()); $records = array(); while($row = mysql_fetch_assoc($result)) { $records[] = $row; } mysql_close($con); echo $_get['jsoncallback'] . '(' . json_encode($records) . ');'; ?>
you can set connection timeout 1 of options. see: http://php.net/manual/en/mysqli.options.php
Comments
Post a Comment