Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

root/Index.php:

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

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

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

Application/global.php:

<?php
require_once 'environment.php';

Application/environment.php

<?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_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $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>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

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

</script>";*/
?>
share|improve this question

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

(1) 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: http://www.phpclasses.org/package/9282-PHP-Log-and-render-current-script-actions.html

(2) 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="127.0.0.1"
    bind-address = ::1
share|improve this answer

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).

share|improve this answer
    
Welcome to Code Review! Your answer would benefit from a bit of formatting and maybe a bit more explanation. – Marc-Andre Feb 19 at 13:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.