php console log speed

How do I log speed benchmarks to a console in php? I don’t want to echo the results for the user to see, but just in some kind of log.

I know that I can get the time elapsed with this:

Read More
$first  = new DateTime( '11:35:20' );
$second = new DateTime( '12:00:45' );

$diff = $first->diff( $second );

echo $diff->format( '%H:%I:%S' ); // -> 00:25:25

but I want to log the time, and not echo it. Do I use the error_log?

Related posts

1 comment

  1. If you will write inside the console of your browser, then use one of a lot of helpers or use a small custom function in php. The follow function is easy to use and log inside the console of the browser.

    if ( ! function_exists( 'debug_to_console' ) ) {
        /**
         * Simple helper to debug to the console
         * 
         * @param  object, array, string $data
         * @return string
         */
        function debug_to_console( $data ) {
    
            $output = '';
            $output .= 'console.info( 'Debug in Console:' );';
            $output .= 'console.log(' . json_encode( $data ) . ');';
    
            echo '<script>' . $output . '</script>';
        }
    }
    

    A image say more:
    enter image description here

    Alternative use a library, like ChromePHP for Chromium Project, Webug for many different browsers or FirePHP as example. Is give a lot more helpers in this topic.

    If you will work this inside WordPress, then is a fast a easy to use helper the plugin Debug Objects, this plugin have the source from the easy to use funtione above inside the plugin and also the CromePHP library.

Comments are closed.