• ollybach

    (@ollybach)


    Hi

    I might be missing something of course and/or it might be intentional but maybe someone can can shed a light on this and/or correct me if I’m wrong

    the following *appears* to be the case.

    when using set_transient with an expiry time in x seconds, the time that seems to be referenced is time() i.e the time the server returns based on the php.ini settings, rather than current_time(timestamp) which would use the time set based on the timezone set in general->settings

    of course, in 99% of the cases this is not that relevant and/or the php.ini has the same timezone set as the settings under general->settings.

    however, i have the following scenario.

    let’s say i need to expire a transient at 4PM depending on the WP-settings timezone, no matter what time it is at the moment.
    so let’s say it is 3PM according to the timezone set in WP i need to expire the transient in 3600 seconds.

    i (believe) normally – when dealing with times/timezones set – I would calculate something based on current_time(timestamp), but if the php.ini is set to another timezone than in WP-settings this calculation would be wrong by one to many hours

    of course, when calculating the transient expiry in this way i could use straight forward time() instead, but it strikes me as odd that for transients it uses time() where everything else uses WP time.

    furthermore, if i were to do that, one day the WP way of setting transients might change to reflect this, so am just trying to ascertain if this is something i should account for somehow.

    as mentioned, most of the time WP time php.ini should probably be the same ind it would not be an issue but it just is not always the case and many people have no idea about timezones in php

    any clarification would be great

    thanks

  • The topic ‘set_transient seem to use server time regardless of timezone’ is closed to new replies.