I have a website where I have around 700 - 1000 users online at all times. Lately I have experienced that my website is getting very slow. There seems to be some sort of bottleneck.
My current setup is I have an index.php
page, which handles all my subpages. The design is like this:
include_once($settings['incpath'].'_ify_database.php');
//Define the extra page levels.
$i = (isset($_GET['i']) ? inputFilter($_GET['i']) : 'h');
$xp = (isset($_GET['p']) ? inputFilter($_GET['p']) : null);
$xpp = (isset($_GET['n']) ? inputFilter($_GET['n']) : null);
switch($i){
case 'h': // Home
include($settings['themespath'].$config['active_theme'].'/indexheader.php');
include($settings['pagepath'].'home.php');
include($settings['themespath'].$config['active_theme'].'/indexfooter.php');
break;
}
This is how I connect to the database (_ify_database.php
):
try {
$dsn = "mysql:host=" . $database['host'] . ";dbname=" . $database['db'];
$dbh = new PDO($dsn, $database['user'], $database['pass'], array(PDO::ATTR_PERSISTENT => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); // <== add this line
}
catch(PDOException $e){
echo $e->getMessage();
}
As you can see, I've set the persistent connection to false
:
PDO::ATTR_PERSISTENT => false
If I enable it to TRUE
I see a good increase in the load time, but after some time I get Too Many Connections
error.
What am I doing wrong? If there is 500 people on the website it's fast. If there is 900-1000 it double it's load time.