[wp-trac] [WordPress Trac] #34322: set_transient and get_transient don't seem to be working for some users since WP 4.3
WordPress Trac
noreply at wordpress.org
Tue Nov 17 02:37:00 UTC 2015
#34322: set_transient and get_transient don't seem to be working for some users
since WP 4.3
--------------------------------+------------------------------
Reporter: smashballoon | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 4.3
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------------+------------------------------
Comment (by smashballoon):
Replying to [comment:4 Nick_theGeek]:
> I think I've found the issue. It is an old problem but the change in
#30380 made it apparent.
>
> Basically the DB limits the option names to 64 characters but by the
time the transient expiration is built for the transients we are using, it
ends up making the string too long. So it searches for something like
_transient_timeout_{long transient name} but the actual option name is
_transient_timeout_{abbreviated transient name}.
>
> Since this doesn't match it returns a "false" value, which is treated as
if the transient will never expire based on the new code.
>
> The solution I came up with was:
>
> {{{#!php
> $transient_timeout = '_transient_timeout_' . $transient;
> $transient_timeout = strlen( $transient_timeout ) > 64 ? substr(
$transient_timeout, 0, 64 ) : $transient_timeout;
> }}}
>
> Well, for my usage, I just shortened the transient name and that fixed
it without editing WP, but while I was testing to find the issue I edited
the option.php file to echo various values and hunt down what was
happening, then applied that to the get_transient() function to verify it
works. Then I reverted all that and changed the length of the transient
key.
I was already limiting the transient name to 45 chars to account for this,
as recommended in the
[Codex](https://codex.wordpress.org/Function_Reference/set_transient). I
ended up giving up trying to figure out why set/get_transient wasn't
working reliably on some servers and just implemented a cron job in the
next plugin update to delete the transients every hour.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34322#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list