Enclosure checks are not known by everybody feature of WordPress website that slows down your website. While optimizing WordPress website for speed we remove any feature or functionality that unnecessarily uses your server resources.
Enclosure checks is one of those features that is not much useful and wastes your server resources hammering overall website performance.
In this tutorial I will show:
- How to view enclosure checks.
- When WordPress checks for enclosures.
- How to optimize your website by blocking most enclosure checks.
Table of Contents
What are enclosure checks?
Enclosure checks in WordPress are the process of checking URLs inside a post. It is done to identify if related content is a video or audio resource. When found, filetype of related resource will be stored in postmeta for future use.
Screenshot from HTTP Requests Manager plugin shows URLs checked for enclosure.
Do not mistake enclosure checks with embedding video or audio content directly into your post. You can insert them in a similar way as you insert images or pasting direct URLs into separate lines. They will use a video or audio player provided by WordPress.
I have not seen any real use for content identified by enclosure checks in WordPress.
When enclosure checks happen?
Enclosure checks are performed every time when you save a post or page. When you save a post, a new cron job will start and check all URLs inside that post for detecting audio and video files.
WordPress sends remote requests (using WP_HTTP) and checks returned headers. Using meta values returned by requested resources WordPress tries to identify their file type.
Then WordPress additionally checks file extension for those URLs.
When URL identified as audio or video WordPress adds record to postmeta
database table. This is some sort of caching for valid URLs.
All other URLs are not stored and will be checked again and again every time you save that post.
Usually when I work on any post I make some changes and save. So a post will be saved at least 10-20 times. Which means all 56 URLs will be checked so many times. Expect 500-1000 enclosure checks
Why are enclosure checks bad for WordPress?
Because it slows down WordPress websites by using resources performing not necessary external requests.
Screenshot shows that 56 enclosure checks performed on a single page. Requests made to 12 different domains.
Enclosure cheeks slow down WordPress in 2 ways:
- Directly: when multiple enclosure checks are performed using WP_HTTP class. Page with 50 URLs will complete checks in 50+ seconds.
- Indirectly: when enclosure check performed for internal page URLs. Every internal page will be generated by WordPress to return response. So if you have 50 URLs to internal pages then 50 pages will be generated consecutively. When an average WordPress page is generated in 1 second your server will be busy for 50+ seconds generating those pages.
These both operations happen simultaneously. Which will peak CPU and RAM usage for your web server.
Because of intensive resource usage you will get 504 “Timeout error”. Or in some cases your web server software will crash. Then you may need to restart PHP workers on your web server.
Now recall how you publish or update your posts in WordPress.
I generally make little changes to content and save posts up to 10 times until I am finally happy with the result. These are minor changes like formating and small fixes.
Having 50 enclosure checks on each save, and saving 10 times means you will have 500 requests.
- 500 requests means 500 pages will be generated.
- Plus 10 pages (cron jobs) will wait until those 500 pages generated.
Which is too much for an unused feature.
How to remove enclosure checks?
You can block enclosure checks using the HTTP Requests Manager plugin.
- Install and activate HTTP Requests Manager plugin from WordPress plugin repository.
- Navigate to “Tools” → “HTTP Requests Manager” page.
- Click on the “Settings” tab and select “Smart Block” for the “Operation mode” field.
- All future external requests will be blocked.
This is an improvement you can expect when “enclosure checks” are blocked. 3.9x performance improvement.
You will see the “block: prevented enclosure_links” badge in your WP_HTTP logs when enclosure checks are blocked.
Which enclosure checks will not be blocked?
Enclosure checks for URLs with corresponding extensions like mp4, mp3 etc. will not be blocked.
WordPress will make external requests to those files. Once identified as a video or image file it will store the result in a database. After which no further “Enclosure Check” requests will be made to those URLs.
Conclusion
Enclosure checks are not an optimized feature of WordPress. You can block most enclosure checks. Saving posts, pages and further WordPress admin area usage will be much faster. Server resources will not be kept busy trying to serve useless requests.
What is next:
- Enclosure checks are initiated and called similar to pingbacks. Check how pingbacks effect WordPress performance.
- Learn how “Smart block” optimizes WP_HTTP requests in WordPress.
- Blocking enclosure checks feature added as a result of WP_HTTP request debugging. View more WP_HTTP debug case studies.
- Learn more about this plugin on the HTTP Requests Manager page.