Bug testing and error finding

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bug testing and error finding

    is there some sort of software or whatever that can detect where errors are, and what can cause problems ie crashes. which = server load and slow responce on webpage?
    Want something coded email me at sales@webnwaphost.com for a prices.





    #2
    i use php designer 2007. with debuger installed.

    Comment


      #3
      n00bs should not apply in your own words ???

      anyway this is not a special software based solution

      1. Learn to optimise, queries in loops are forbidden, never do it, what i do is use a mysql query function on large sites to view queries, something like

      Code:
      function sql_query($query) {
       global $queries, $query_stat;
       if(!isset($queries))
        $queries = 0;
       if(!isset($query_stat))
        $query_stat = array();
       $queries++;
       $mtime = microtime(); // Get Current Time
       $mtime = explode (" ", $mtime); // Split Seconds and Microseconds
       $mtime = $mtime[1] + $mtime[0]; // Create a single value for start time
       $query_start_time = $mtime; // Start time
       $result = mysql_query($query); // do not change to sql_query
       $mtime = microtime();
       $mtime = explode (" ", $mtime);
       $mtime = $mtime[1] + $mtime[0];
       $query_end_time = $mtime; // End time
       $query_time = ($query_end_time - $query_start_time);
       $query_time = substr($query_time, 0, 8);
       $query_stat[] = array("seconds" => $query_time, "query" => $query);
       return $result;
       }
      then at the bottom of the page a box with all the queries in

      Code:
      if($userid == 1) {
            foreach($query_stat as $key => $value)
             print("[".($key+1)."] => <b>".($value["seconds"] > 0.01 ? "<font color=\"red\" title=\"I suggest you should optimize this query.\">".$value["seconds"]."</font>" : "<font color=\"green\" title=\"This query doesn't need's optimization.\">".$value["seconds"]."</font>" )."</b> [$value[query]]<br />\n");
      
      }
      What that will do it print out each query and the time it took to execute with a colour to tell you if its quick or slow (some queries will be inheriently slow and impossible to fix but most should be optimisable). Its a nifty bit of code and simple to use, just replace your mysql_query with sql_query

      2. enable slow query logging in my.cnf (mysqls config file). This will log any queries that take longer than x seconds (x is defined in my.cnf) to execute. Pretty much like above but more accurate and it never hurts to have extra logging

      3. in php.ini or at the start of one of your main include files like core.php add
      Code:
      error_reporting(E_ALL);
      ini_set("display_errors",1);
      That will simply tell php to output any warnings or errors to the screen, if you havent done this before be prepared for a boat load of warnings for undefined vars e.c.t. most of which are fixed by simply initiating the variable and/or using isset() ).

      4. if you have shell access you can use the top command to give you an idea of if its a mysql or apache issue (you can also tell if its a php issue if php is running in cgi, you run php as a apache module then php is part of the apache process so there not seperately shown). Soo you could either just type
      Code:
      top
      for a list of processes or type something like
      Code:
       top -u www-data
      to see all running processes under the www-data user which is the common username for apache

      thats more than enough to get you going, there is a hell of a lot more you could do but the above are usually enough to satisfy most people.

      Comment

      Working...
      X