Code:
<?php
ini_set('default_charset', 'UTF-8');
if(function_exists('mb_internal_encoding')) {
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
}
date_default_timezone_set('America/New_York');
define('SITE_CACHE_ID', '0');
require_once('dbconnect.inc.php');
require_once('cacheDatabaseFunctions.inc.php');
require_once('generalFunctions.inc.php');
...
?>
dbconnect.inc.php is the first file required
Code:
<?php
try {
$pdo = new PDO("mysql:dbname=alicenet;host=localhost;charset=utf8", "user", "pass");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}
catch(PDOException $e) {
print('Database Connection Failure');
}
?>
Vast majority of time no issues.
Every now and then, a page won't load, and when I look in my error logs:
Code:
PHP Notice: Undefined variable: pdo in .....
It's not often but seems (not scientific) to be most likely to happen if the server has been under load.
So it seems that sometimes the dbconnect.inc.php script has not finished by the time another script required after it tries to use the $pdo handler.
Is there something I'm missing? I thought php loaded required files in serial. Is that incorrect?
php 5.6.5 (but has happened in every 5.6.x) x86_64 on CentOS 7