Bulk Actions: use JavaScript to execute actions and provide real-time feedback
WordPress 4.0.1
Broken Link Checker 1.10.3
When I perform an action on an individual link, BLC uses JavaScript to execute the action without refreshing the web page. This gives me a real-time indication of the status of the action. When it is complete, the individual link is updated on the page.
In contrast, if I use the Bulk Actions menu and button, BLC sends the commands to the server and asks to refresh the page. The page is not refreshed until all commands have completed.
There are a few small advantages to making the Bulk Actions commands invoke the JavaScript (when available, of course). Counter-intuitively, the JavaScript is less likely to produce a 500 or 501 error on weak servers. On weak servers, such as my free-with-domain-registration GoDaddy.com shared hosting, if a single POST/GET requires more than X seconds, then the either WordPress or Apache will produce a 500 or 501 error. If my Bulk Actions request is large, then my server will lock up until the command is complete. By using the JavaScript, the client would parse the Bulk Actions request into atomic requests, send each request in series, update the page as each request is completed, and, importantly, not lock-up the server while the series of requests is being executed.
A second advantage is that when I get a real-time status of my Bulk Actions command.
-
Hunter Hogan commented
Absolutely. The AJAX approach is certainly more total load on the server: probably many times more. The only advantage, if there is one, is the serialization of the requests. Hmm. That gave me a thought. You already have code for throttling the tool based on server load. I wonder if you could throttle the ... meh, this is too complicated.
My situation is almost certainly a corner case: I have thousands of posts, tens of thousands of media files, a couple thousand external links, and a server that cannot handle what I am trying to do. I doubt most people push their WP installation as hard as I push it, so after thinking more about it, I doubt that my above idea is a good idea.
-
AdminJānis Elsts (Admin, W-Shadow.com) commented
Both approaches have their trade-offs. I suspect that sending 100 AJAX requests that each process one link would take significantly more time and cause more server load than batch-processing 100 links in one request.
Each request has a considerable overhead: load and run WordPress files, connect to the database, load the current theme, load all active plugins, do a bunch of pre-processing to determine which plugin/hook should handle the request, check user permissions, etc. Doing all of that only once is more efficient than repeating the entire process for each link.