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

  • SEARCH
  • Home
  • 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 6692971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:55:44+00:00 2026-05-26T05:55:44+00:00

According to the gmmktime() description in the PHP manual, it uses mktime() internally. Yet

  • 0

According to the gmmktime() description in the PHP manual, it uses mktime() internally. Yet when I run the following code, the mktime loop takes just under 9 seconds to run while the gmmktime look takes just under 2 seconds. How can this be?

<?php
$count = 1000000;

$startTime = microtime(true);
for ($i = 0; $i < $count; $i++)
{
  mktime();
}
$endTime = microtime(true);
printf("mktime: %.4f seconds\n", $endTime - $startTime);


$startTime = microtime(true);
for ($i = 0; $i < $count; $i++)
{
  gmmktime();
}
$endTime = microtime(true);
printf("gmmktime: %.4f seconds\n", $endTime - $startTime);

Output:

mktime: 8.6714 seconds
gmmktime: 1.6906 seconds
  • 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-26T05:55:45+00:00Added an answer on May 26, 2026 at 5:55 am

    Most likely, the documentation is lying to you about how gmmktime() is implemented – or it means the C function mktime() is being used.

    If we look at the actual code, both gmmktime() and mktime() pass through to an internal php_mktime function, which takes a gmt parameter (set to 1 for gmmktime()). If gmt is zero, then it has to do some extra work (//-comments I have added, others from original code):

    /* Initialize structure with current time */
    now = timelib_time_ctor();
    if (gmt) {
        timelib_unixtime2gmt(now, (timelib_sll) time(NULL));
    } else {
        tzi = get_timezone_info(TSRMLS_C);
        now->tz_info = tzi;
        now->zone_type = TIMELIB_ZONETYPE_ID;
        timelib_unixtime2local(now, (timelib_sll) time(NULL));
    }
    
    // ... snip shared code
    
    /* Update the timestamp */
    if (gmt) {
        // NOTE: Setting the tzi parameter to NULL skips a lot of work in timelib_update_ts
        // (and do_adjust_timezone)
        timelib_update_ts(now, NULL);
    } else {
        timelib_update_ts(now, tzi);
    }
    
    /* Support for the deprecated is_dst parameter */
    if (dst != -1) {
        php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The is_dst parameter is deprecated");
        if (gmt) {
            /* GMT never uses DST */
            if (dst == 1) {
                adjust_seconds = -3600;
            }
        } else {
            /* Figure out is_dst for current TS */
            timelib_time_offset *tmp_offset;
            tmp_offset = timelib_get_time_zone_info(now->sse, tzi);
            if (dst == 1 && tmp_offset->is_dst == 0) {
                adjust_seconds = -3600;
            }
            if (dst == 0 && tmp_offset->is_dst == 1) {
                adjust_seconds = +3600;
            }
            timelib_time_offset_dtor(tmp_offset);
        }
    }
    

    I suspect what you may find is that, every time you do mktime(), it reopens the timezone description file to read it and get the proper timezone/DST offsets. By using gmmktime(), it skips that by using an internal null timezone for GMT – thus, much faster.

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

Sidebar

Related Questions

According to what I have found so far, I can use the following code:
according to this description I just created an nine-patch image. I named it androidRow.9.png
According to the manual , git dcommit will create a revision in SVN for
according to my knowledge, this feature already exists in PHP. lets look at the
According to the PHP Documentation PDO::prepare() adds quotes to all your parameters so that
According to http://msdn.microsoft.com/en-us/library/ms535934(v=VS.85).aspx and http://msdn.microsoft.com/en-us/library/ms535262(v=VS.85).aspx , I should be able to do the following
According to this discussion , the iphone agreement says that it doesn't allow loading
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to
According to MSDN form.RightToLeftLayout = True; form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False; is
According to select name from system_privilege_map System has been granted: SELECT ANY TABLE ...and

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.