How to decode Base64 to original String?

Is there a way to avoid getting "WordPress database error: [MySQL server has gone away]" when setting a very long string with set_transient()?

  • When I set a very large base64 encoded string into a transient with set_transient(), I got: WordPress database error: [MySQL server has gone away] INSERT   INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES  ('_transient_93a988641ef89c6a4277580c79e63bf4',  'a:2:{s:3:\"aaa\";i:1379621118;s:4:\"bbbb\";s:1109240:\"YToxMDA6e2k6MDthOjIzOntzOjEwOiJjcmVhdGVkX2F0IjtzOjMwOiJUaHUgU2VwIDE5IDE3OjE3OjQ2ICswMDAwIDIwMTMiO3M6MjoiaWQiO2Q6MzgwNzQyNTI0Mjc4NTY2OTEyO3M6NjoiaWRfc3RyIjtzOjE4OiIzODA3NDI1MjQyNzg1NjY5MTIiO3M6NDoidGV4dCI7czoxNDI6IlJUIEBEYWlseW5pY2ViYWJlczogQFNvZnQwOXIgQFBvcm5QaWNhIEBJRG9Mb3ZlSG90dGllcyBAa2FyaW5hd2hpdGVmYW5zIEBPb2hGZWxsYXRpbyBAUmVhbEdpcmxzNiBAVmFsX1N5dGhlcmlhIEBWaW5hdXNleHh4IEA2OXNleHh4byBodHRwOi/igKYiO3M6Njoic291cmNlIjtzOjYzOiI8YSBocmVmPSJodHRwOi8vd3d3LnR3ZWV0ZGVjay5jb2... So I set max_allowed_packet from max_allowed_packet = 1M to max_allowed_packet = 16M in my.ini, which is the MySQL setting file, and the error has gone. As I searched the web, max_allowed_packet cannot be set in PHP. The set string is a generated data and cannot be chopped. I'm wondering if there is a workaround.

  • Answer:

    Do you need to use the Transients API? Could you perhaps try using the options API instead? From memory the option_value database field is a field of type text which means it can hold a lot of data. The difference between the two is transients are temporary and expire, options do not expire. But it would be easy to remove the data once you're finished with it.

Dwayne Charrington at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.