Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:31:41+00:00 2026-05-13T23:31:41+00:00

What is the best way to see how long it takes for your PHP

  • 0

What is the best way to see how long it takes for your PHP script to run?

I was thinking something like this:

$start_time = time(); //this at the beginning
$end_time = time(); //this at the end
echo = $end_time-$start_time;

But how can I make it into something that is readable to me and make sense to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:31:42+00:00Added an answer on May 13, 2026 at 11:31 pm

    If you want any further granularity to your timing than seconds, you’ll need to use microtime() (Return current Unix timestamp with microseconds)

    <?php
    $time_start = microtime(true);
    
    // Sleep for a while
    usleep(100);
    
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    
    echo "Did nothing in $time seconds\n";
    ?>
    

    ** Below was added later **

    As far as formatting this result further:

    Well, depending on what you’re doing, you typically don’t have scripts going past a minute. You definitely shouldn’t have anything exceeding an hour. (If you do, you need to ask yourself what you are doing with your life)

    With that in mind, all you need is simple calculations:

    $tmp = floor($time);
    $minutes = $tmp / 60;
    $seconds = ($tmp % 60) + ($time - $tmp);
    
    $output = 'Script took ';
    if ($minutes > 0)   $output .= $minutes . ' minutes and ';
    $output .= $seconds . ' seconds to complete.';
    echo $output;
    

    (This isn’t tested, and it could potentially be optimized, but should start you in the right direction)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the best way to see if the current time lies between
I would like to see best way of posting to Facebook from a HTML
I would like to see the best way to create a where statement with
For a long time i have tried to work out the best way to
What's the best way to see a webpage's speed in IE7+? For Firefox, there's
What would be the best way to see if an NSDate is actually set
what do you see as best way of presenting class names in LaTeX documents
Is there a best (see below) way to append two byte arrays in C#?
The best way I think to explain this is to tell you what my
resizing a camera UIImage returned by the UIImagePickerController takes a ridiculously long time if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.