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 8522747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:12:47+00:00 2026-06-11T07:12:47+00:00

Are there limitations for strings used for options? I’m tyring to use the Transient

  • 0

Are there limitations for strings used for options? I’m tyring to use the Transient API and when I inlude a string of url in the transient name, it does not save the data. I’m not sure if it is due to a character length or illegual characters.

$url = 'http://stackoverflow.com/questions/tagged/php+wordpress+wordpress-plugin';
$strTransient = 'sample_transient_' . $url;
$key = 'sample_transient';
$html = get_transient($strTransient);   
if( false === $html ) {
    echo 'cache is not used: ' . $strTransient . '<br />';      
    $html = wp_remote_get($url);    
    $html = $html['body'];  
    $savehtml = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $html, MCRYPT_MODE_CBC, md5(md5($key))));
    set_transient($strTransient, $savehtml, 60 );
} else {
    echo 'cache is used. <br />';
    $html = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($html), MCRYPT_MODE_CBC, md5(md5($key)));  
}
print_r($html);

Thanks in advance.

[Edit]

It seems to be due to the character length.

$transientkey = 'verylongstring_verylongstring_verylongstring_verylongstring_verylongstring_verylongstring_verylongstring'; // <-- fails
// $transientkey = 'shortstring';   // <-- okay

$data = get_transient($transientkey);   
if( false === $data ) {
    echo 'transient is not saved: ' . $transientkey . '<br />';     
    $data = 'hello world!';
    echo 'now saving the data.<br />';
    set_transient($transientkey, $data, 60 );
} else {
    echo 'transient is used. <br />';
}
print_r($data);

So where can I find the exact information about the limitations for option keys? I could not find it in the core. This is the comment for set_transient()

wp-includes/option.php

/**
 * Set/update the value of a transient.
 *
 * You do not need to serialize values. If the value needs to be serialized, then
 * it will be serialized before it is set.
 *
 * @since 2.8.0
 * @package WordPress
 * @subpackage Transient
 *
 * @uses apply_filters() Calls 'pre_set_transient_$transient' hook to allow overwriting the
 *  transient value to be stored.
 * @uses do_action() Calls 'set_transient_$transient' and 'setted_transient' hooks on success.
 *
 * @param string $transient Transient name. Expected to not be SQL-escaped.
 * @param mixed $value Transient value. Expected to not be SQL-escaped.
 * @param int $expiration Time until expiration in seconds, default 0
 * @return bool False if value was not set and true if value was set.
 */

Also any suggestion to identify a url as a transient key?

  • 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-06-11T07:12:49+00:00Added an answer on June 11, 2026 at 7:12 am

    The documentation says the transient name is “Expected to not be SQL-escaped. Should be 45 characters or less in length.“

    Looking at the table structure in WordPress 3.4.1:

    mysql> desc wp_options;
    +--------------+---------------------+------+-----+---------+----------------+
    | Field        | Type                | Null | Key | Default | Extra          |
    +--------------+---------------------+------+-----+---------+----------------+
    | option_id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
    | option_name  | varchar(64)         | NO   | UNI |         |                |
    | option_value | longtext            | NO   |     | NULL    |                |
    | autoload     | varchar(20)         | NO   |     | yes     |                |
    +--------------+---------------------+------+-----+---------+----------------+
    4 rows in set (0.00 sec)
    

    So the option_name can be no longer than 64 characters, but the data can be as large as 232 bytes (~4GB). set_transient ultimately calls add/update_option which can have an option name up to 64 characters long, but since the transient works in a special way, 45 is the longest value you should use.

    EDIT:

    From looking at the WP code, the reason the transient name is restricted to 45 characters per the reference guide is because the code does this:

    $transient_timeout = '_transient_timeout_' . $transient;
    //...
    add_option( $transient_timeout, time() + $expiration, '', 'no' );
    

    So if you pass hello as the transient, it will add an option called _transient_timeout_hello. Given that: 45 + strlen('_transient_timeout_') === 64 and 64 is the maximum varchar length of the option name field in the WP options table.

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

Sidebar

Related Questions

Are there different limitations as to how many connections (sockets) that can be created
Is there any limitations on AJAX Calls with ScriptManager to Web Services? I have
When adding code to an onclick handler, are there any limitations to what can
Other than Active Sync not working, are there any other limitations that I need
Is there anything I might regret later, i.e. any major limitations if we choose
There seem to be a limitation in the maximum number of clickable options in
If there are some kind of limitations for array keys in PHP ? Length
Is there absolutely no way to have a property of a string type as
I would like to remove the query string from the URL using mod_rewrite (.htaccess),
Is there such a thing? I've been looking around the Vala API and the

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.