WordPress Plugins utilizing admin-ajax.php causing Performance Issues

Content Error or Suggest an Edit

Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!

Introduction

The following article provides information on the WordPress admin-ajax.php function and a list of WordPress Plugins using admin-ajax.php in a manner that results in performance issues with your WordPress site.

What is admin-ajax.php

The “admin-ajax.php” file handles asynchronous requests made by both administrators and visitors of a WordPress website. It is an endpoint for various AJAX (Asynchronous JavaScript and XML) calls made by the WordPress admin area and front-end components.

AJAX allows websites to communicate with servers in the background without reloading the entire page. It enables the creation of dynamic and interactive web applications. WordPress leverages AJAX to enhance the user experience by providing features like live updates, form submissions without page reloads, and more.

When an AJAX request is made to admin-ajax.php, WordPress examines the request to determine the appropriate action to perform. The request includes parameters such as the action name and any additional data required to process the request.

WordPress provides various hooks and actions developers can use to extend its functionality. In the case of admin-ajax.php, these hooks allow developers to register their custom AJAX actions and associate them with specific functionalities.

Source: https://kinsta.com/blog/admin-ajax-php/

Performance Issues with admin-ajax.php

Why does using admin-ajax.php cause performance issues? The following two articles go in-depth into why admin-ajax.php should be avoided completely when developing a plugin, especially for any front-end non-logged-in requests.

Videos

WordPress Performance Team Github Issue

The following Github issue is the first step in solving the performance issues with admin-ajax.php

Feature request: High Performance AJAX · Issue #586 · WordPress/performance · GitHub
Feature Description There are some gists out there demonstrating how the highly-utilized admin-ajax.php can be sped up for frontend requests with a few tweaks, disabling certain admin actions/hooks. According to the original gist, this c…
github.com

Logging admin-ajax.php Requests

If you’re in a position where you’re seeing many admin-ajax.php requests in your access log and your WordPress site is slow or you want to know more about the requests. There is no native method in WordPress to investigate these requests, so I decided to make a mu-plugin that logs each request to a log file.

You simply drop the ajaxlog.php script into your wp-content/mu-plugins folder and then a log will be generated within the same folder.

Attention

It’s suggested to remove the ajaxlog.php file after you’ve gathered the data you require, and delete the log file from your server.

wordpress-code-snippets/ajaxlog at main · managingwp/wordpress-code-snippets · GitHub
Code snippets for WordPress. Contribute to managingwp/wordpress-code-snippets development by creating an account on GitHub.
github.com

Potential Solutions

Short Term Unstable

As mentioned in the GitHub issue, there was a gist that has now been forked and updated to work with WordPress 6.1 that is a drop-in replacement for admin-ajax.php

WordPress : A drop-in replacement for admin-ajax.php that is optimized for visitor-only AJAX requests. · GitHub
WordPress : A drop-in replacement for admin-ajax.php that is optimized for visitor-only AJAX requests. – wp-ajax.php
gist.github.com

I haven’t tested this, so you must use this code carefully.

Long Term Solution

The long-term solution is most likely to build a user-ajax.php handler that is bare-bones and performant. The admin-ajax.php is still required for backend-related actions that require more code than a front-end request. This is just a suggestion. Hopefully, the WordPress performance team will figure out something.

Problematic Plugins Using admin-ajax.php

Changelog

  • 03/10/2023 – Added WordPress Performance team Github Issue.
  • 04-17-2023 – Added additional video and embedded Youtube videos.
0 Shares:

You May Also Like
Read More

Why should you use sudo?

Introduction There was a question on the popular GridPane Facebook Group asking about login in as the system…