If you do a general search on the “Fatal error: Maximum execution time of 30 seconds exceeded ” error you will find it is a very common event. It may cause a site to come down for 2-3 minutes. Ten minutes downtime is possible if your a frequent offender. The fatal error is the server taking control of the situation and the limit, which is often 30 seconds. Is in place for both security and to reduce bandwidth usage on shared servers, something experienced on low cost hosting.
The cause is either a fault where a loop never ends and is meant to or in the case of a plugin like CSV 2 POST it is caused when the user requests the plugin to create more posts than their server can handle in one go. That is why we have the ability to break it down and create maybe 1000 posts at a time.
We are always working to improve that number. The most simple script can create 1 million posts in 30 seconds but they are basic posts on the most basic blogs.
Reduce Processing Time
There is a not lot of scope for using functions just for the sake of it but there is a gradual use of switches in the plugin that active functions i.e. once switched on certain functions will come into play during post creation. An example is text spinning, which most users will not use and so we first need to submit a form to switch text spinning on. This then puts all post content through text spinning functions.
Some things you can do to reduce processing time per post…
- Do not use functions in CSV 2 POST unless you really need them i.e. do not switch them on in Your Project configuration unless you intend to use the related feature or just remember to switch them back off.
- Process media first i.e. if you need your images to be cropped to various sizes including for the use as feature images you can upload them all in a batch fashion and have the images ready to be attached to new posts.
- Disabled plugins that react to anything being created should be disabled where possible. Twitter plugins are a big no unless automatic tweeting is off. Even if a schedule system is available for a tweets that is still extra work for WordPress during the creation of hundreds of posts.
- Switch pinging off and any other similiar services that update external domains.
Categories First Posts Second
As of 15th February 2013 CSV 2 POST makes users create their categories prior to posts being created to help reduce processing time. We may be able to take this approach with other elements of a post, one step at a time though.
Insight Into WordPress Post Creation
The average user won’t know what happens per post in terms of server processing and database queries. Some understanding into this helps to manage a plugin like CSV 2 POST which lets face it, uses WordPress in a way it was not designed for. Developers of WordPress do not put protection in place for a “Maximum execution time of 30 seconds”.
WordPress In Normal Use
WordPress was designed for manually creating posts and there is no way of getting around the fact that a single post requires multiple database queries. Plus with a lot of plugins installed we may increase processing time when extra things are done in reaction to a post being published i.e. a Twitter plugin may send a tweet or schedule one to be tweeted. Here are some of the queries WordPress might perform when manually creating a post…
- Permalink is established using Ajax straight away but it does require two queries.
- Tags are also stored prior to the Edit Post screen being submitted and post being published. But again more queries are done.
- Featured image requires a locally stored image, usually cropped to fit the theme and a query is made to the database to attach the media to the post.
- Media itself is stored in the database and that may require many queries
- Custom fields on the Edit Post screen are processed using Ajax so once again there is work for WordPress to do and it gets done as we go along.
- Now we submit our post and a query is done to store content.
- If we used categories a query is done to update a categories post counter, I think. It has been a while since I looked at this but it is a good example of how the smallest things require some communication with the database.
So keeping in mind that this is WordPress in normal use, a manually created post by a user who…is not Data on the Enterprise put it that way. No user will make all of the above queries happen within a second but software can make them all happen in even less of a second.
Auto-Blogging Plugins
Auto-blogging can trigger this error very easily, especially on slower servers. The slower a server, the longer it takes to create just a few hundred posts and it uses up extra seconds. A great mass posting plugin like CSV 2 POST with all its advanced features takes even longer, if you use those features that is.
It is important to understand that CSV 2 POST uses WordPress core functions to create posts. All values are processed through WordPress functions so that plugins can get their chance to do what they are meant to do during post creation. The main reasons however are for the sake of standards and security.
Here is the above list of processes again but from an auto-blog perspective…
- Permalink is established at the same time as everything else. Meaning WordPress needs to query existing permalinks and establish a unique one before allowing the post to be stored in the database. Keep in mind, a draft is also created, there is no way around that because we need to secure our post ID and permalink. Permalink features in CSV 2 POST may add further processing.
- Tags don’t cause a query to be performed, we simple built the string of tags. However use of all settings will increase processing time per post especially if we automatically extract tags from snippets of text content.
- Featured images and any media processing may involve new files being created, queries to media related data and there is a good chance that other plugins or themes will be included in the process.
- Custom fields offer support for many advanced features in CSV 2 POST. We need to store various data to track a posts history and more. We can easily add an extra 10 custom fields per post if we use the full scope of this plugins abilities. The abilities are great and I wouldn’t avoid using them for the sake of processing time but it is a fact that each custom field requires a new record in the database.