用于选项的字符串是否有限制?我很想使用瞬态 API,当我在瞬态名称中包含一串 url 时,它不会保存数据。我不确定这是由于字符长度还是非法字符。
$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);
提前致谢。
[编辑]
这似乎是由于字符长度。
$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);
那么我在哪里可以找到有关选项键限制的确切信息?我在核心中找不到它。这是评论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.
*/
还有任何将 url 标识为临时密钥的建议吗?