Small PHP CMS base

Posted on


I am a bit worried about this small PHP base as it has been running a bit slow. Can anyone notice anything majorly wrong with it?


define('START', microtime(true));
define('RAM', memory_get_usage(true));
define('ROOT', dirname(__FILE__) . '/');
define("SECURE", true);

ini_set('date.timezone', 'Europe/London');

include_once ROOT . '/application/global.php';


require_once 'environment.php';


require_once 'autoloader.php';
require_once 'include/config.php';

if (!isset($config))
    exit('Unable to load configuration data.');

function rutime($ru, $rus, $index) {
    return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))
     -  ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000));

try {
    $dns = "mysql:host=".$config['database']['host'].";dbname=".$config['database']['name']."";
    $pdo = new PDO($dns, $config['database']['username'], $config['database']['password']);
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
catch (PDOException $ex) {
    exit('Unable to connect to the master database! ' . $ex);

$c = new Core($config, $_GET['page'], new User($pdo), new Form(), $pdo, new template());

// Google Analytics
/*echo "<script>
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-73890636-1', 'auto');
  ga('send', 'pageview');



It is difficult to say by just watching the code lines.

You can measure line by line. I wrote a simple class to add a message whenever you want. The render method draws an html table an shows the diff time between each message:

If the connect time to mysql is about 1 sec and the database is on localhost, then verify mysql settings bind-address in my.cnf. Remove localhost and set the ip, i.e.

    bind-address = ::1

start by changing your syntax values. there too close. mention time break, allow the program to be illogical. also error messages are key to understanding and troubleshooting, please detail the error(s).

Leave a Reply

Your email address will not be published. Required fields are marked *