// init sessions session_start() or die("Failure Starting Session"); // includes require("inc/config.php"); require("inc/functions.php"); // prevent browser cacheing header("Cache-Control: no-cache"); // connect to database mysql_connect($sqlhost, $sqluser, $sqlpass) or die(mysql_error()); mysql_select_db($sqldb) or die(mysql_error()); if (ENABLE_SQL_PROFILER) { mysql_query("SET PROFILING = 1"); /** * A function to collect and write the profiling info to * a log file. It'll be executed when the script execution * ends. (See below the function.) */ function write_to_log() { $profilingResult = mysql_query("SHOW PROFILES"); if ($profilingResult) { // Collect the duration info $queryCount = 0; $totalDuration = 0.0; while ($row = mysql_fetch_assoc($profilingResult)) { ++$queryCount; $totalDuration += (double)$row["Duration"]; } // Stop profiling mysql_query("SET PROFILING = 0"); // Write the profiler data to the log file. // Note that the CWD of a shutdown function is not // reliable. Use an absolute path to the log file. $filePath = "inc" . "/mysql_profiler.log"; $line = sprintf("Count: %d, duration: %.9f\n", $queryCount, $totalDuration); if (!file_put_contents($filePath, $line, FILE_APPEND)) { trigger_error("Failed to write to log file. Check permissions!", E_USER_ERROR); } } else { trigger_error("SHOW PROFILES query failed: " . mysql_error(), E_USER_ERROR); } } // Register the write_to_log function up to be executed when the // PHP script execution is about to end. All queries your code // will execute should be done at this time, so the profiling // info will be complete. register_shutdown_function('write_to_log'); }
After this, I pretty much go straight into logging into the system
if($_POST['login_username']){ // get posted details $login_username = mysql_real_escape_string($_POST['login_username']); $login_password = mysql_real_escape_string($_POST['login_password']); // query database for matching active user $result = mysql_query("SELECT `id`,`loginstatus` FROM `users` WHERE `username`='".$login_username."' AND `password`='".$login_password."'"); ...
Then, it pretty much gives the user a session and loads a lot more php files and other things. Now, I dont know if what I done at the top is enough to profile all queries in every php file, or if I need more. At the moment, I do get data written to my file, but its pretty much
Quote
Count: 0, duration: 0.000000000
Count: 15, duration: 0.000881000
Count: 15, duration: 0.000162000
Count: 15, duration: 0.000184000
Count: 15, duration: 0.000186000
Count: 15, duration: 0.000921000
Count: 15, duration: 0.000896000
Count: 15, duration: 0.001320000
Count: 15, duration: 0.000193000
Count: 15, duration: 0.000180000
Count: 4, duration: 0.015574000
Count: 0, duration: 0.000000000
Count: 15, duration: 0.000881000
Count: 15, duration: 0.000162000
Count: 15, duration: 0.000184000
Count: 15, duration: 0.000186000
Count: 15, duration: 0.000921000
Count: 15, duration: 0.000896000
Count: 15, duration: 0.001320000
Count: 15, duration: 0.000193000
Count: 15, duration: 0.000180000
Count: 4, duration: 0.015574000
Count: 0, duration: 0.000000000
Also, when I look for examples online, they all use the command line to set profiling to 1, but everything I am doing is on a live server, so I dont think I can or need to do this. Does it look like I am getting the right results and is there anyway to get the name of the query being profiled? Any advise appreciated
Cheers