I am about to create a new plugin that fetches remote content and stores it locally for use on the WP website. I have a free plugin that does this with twitter and tweets, and I store a JSON file in the plugin directory. Some users complain that the plugin cannot write files to the folder due to permissions.
For this reason, I have been thinking about storing the remote content for this new plugin in an option. Is 250kb of HTML too big for an option? Is there another API call that can help me store a large chunk of string data?
Look at the table schema in
wp-admin/includes/schema.php
:In both cases the value is
longtext
. The MySQL manual says about that type:4GB. If that is not enough improve the clean-up process. Maybe you should store the content as a file anyway â in the
uploads
directory.It’s a longtext field…
…and that means it can hold about 4 gigabytes. https://stackoverflow.com/a/4294527/751089
IMHO this is a perfectly good use for an option as the information isn’t related directly to eg a post or a user. In general it’s not a good idea to store masses of data in one field, but then tweets are very replaceable.
Finally, for storing tweets and other changing data that’s a bit slow to get hold of you may want to look at the Transients API, which can assist you with refreshing them at intervals.
While it’s true that it’s a
LONGTEXT
column, which can theoretically hold up to 4GB, you also need to take into account MySQL’s “max_allowed_packet” size.The setting “max_allowed_packet” limits how much data can be sent in a single MySQL query and its default value is only 16MB.
Most shared hosts won’t let you change that value. And even then, the maximum value you can set in MySQL is 1GB.
So for a plugin that you hope will work on most shared hosts, WP options shouldn’t be larger than 16MB.