How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

fileAdmin-ajax.php Plays a key role in WordPress websites, it's the core file that manages AJAX requests and allows you to implement dynamic features such as real-time notifications, asynchronous form submissions, infinite scrolling, and more without having to refresh the entire page.

(coll.) fail (a student) admin-ajax.php When overused, it can becomeLeads to degradation of website performanceof the culprits. This article will delve into the admin-ajax.php features, the performance impact of their overuse, and help you diagnose and fix related issues so you can keep your WordPress site performing at its best.

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

What is admin-ajax.php?

admin-ajax.php is a WordPress core file that handles all of the site's AJAX Request. It is the equivalent of a messenger that passes data between the page and the server without reloading the entire page.

Main function of admin-ajax.php

  • Supports asynchronous communication: AJAX (Asynchronous JavaScript and XML) allows websites to send and receive data to and from the server without refreshing the page, thus enhancing the user experience.
  • multitasking: admin-ajax.php Handles a variety of backend tasks such as submitting forms, loading comments, dynamically updating content, enabling infinite scrolling, and displaying real-time notifications.
  • act as an intermediary: When a plugin or theme needs to run certain operations in the background, it sends AJAX requests via admin-ajax.php, which processes them and returns the necessary data.

admin-ajax.php is the key to many of WordPress' dynamic features.

admin-ajax.php high usage on WordPress websites

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

admin-ajax.php Dynamic functionality is crucial for WordPress sites, but its overuse can lead to serious performance issues. Here's how high usage can affect a website:

  1. Increase server load: Each AJAX request willConsumption of server resourcesThe server may not be able to cope with the number of requests, such as CPU and memory. When the number of requests is too high, the server may not be able to handle it, resulting in a slower response time or even a crash of the website.
  2. Slow page load: When admin-ajax.php handles a lot of requests, the page load time can increase significantly. This can negatively impact user experience and potentially hurt your SEO rankings.
  3. Website instability: Excessive use of admin-ajax.php may cause "500 Internal Server Error" or timeout issues, which can make the site unstable.
  4. Poor user experience: Due to overloading of admin-ajax.php, the site is running slowly and functions are not responsive, resulting in a degraded user experience, which in turn may increase the bounce rate.
  5. plug-in conflict: Some poorly coded plugins may trigger too many AJAX requests, compounding the problem.
  6. security hole: Although uncommon, unoptimized AJAX requests can increase security risks.

How to diagnose high usage of admin-ajax.php on WordPress websites?

In order to find out admin-ajax.php The root cause of overuse, there are a variety of tools that can be used to help you analyze your website's performance. Here are a few recommended tools:

1. GTmetrix

GTmetrix is a website performance analysis tool that can be used to see if admin-ajax.php is negatively affecting the performance of your website. The procedure is as follows:

  1. interviews GTmetrix website and log in.
  2. Enter the URL of the website and click Test NowThe
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. After running the performance check, go to Waterfall(Waterfall Diagram) tab, Search admin-ajax.phpThe
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. Look at the load time for this request, if it is significantly longer than the other requests, it means that the script may be causing performance issues.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

2. Chrome Developer Tools

Chrome's Developer Console is also a very effective tool you can use to detect admin-ajax.php The use of the

  1. Visit your website, right-click on the page and select probeThe
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. switch to Network(Network) tab and reload the page.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. In the filter box, enter admin-ajaxYou can view the details of the request.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

With these tools, it is possible to determine which requests are causing performance problems and begin to address them.

How to reduce the high usage of admin-ajax.php in WordPress?

Fixing high usage issues with admin-ajax.php depends on the exact cause. Here are some common solutions:

1. Disable problematic plug-ins

If a plugin is generating too many AJAX requests, the problem can be solved by disabling the plugin. You can disable plugins one by one and observe changes in site performance to determine the culprit. If the problematic plugin is found, you can contact the plugin developer or look for an alternative.

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

2. Enable Cache

Enabling caching significantly reduces server load and reduces dependency on admin-ajax.php requests. By storing static versions of website pages, caching reduces repetitive database queries and AJAX requests. Recommended Usage W3 Total Cache maybe WP Super Cache plugin to manage the cache. Select "Delayed image loading" feature can further optimize performance.

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

3. Controlling the WordPress Heartbeat API

WordPress Heartbeat API implements real-time communication between the browser and the server, but it can cause the admin-ajax.php Excessive usage. It is possible to use Heartbeat Control maybe LiteSpeed Cache plugin to limit the frequency of the Heartbeat API and reduce the impact on the server.

move::

  1. Installation and activation LiteSpeed Cache Plug-ins.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. In the WordPress backend, navigate to LiteSpeed Cache > Toolbox > HeartbeatThe
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. Turn on Heartbeat control and adjust the TTL value to control the communication frequency.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. Enable Heartbeat control and adjust TTL
    • exist Heartbeat Several control options can be seen in the settings:
      • Enable/Disable Heartbeat: Enable or disable the Heartbeat API for WordPress.
      • TTL (Time-to-Live) Settings: Adjusts the frequency of Heartbeat API calls (i.e., the time between communications.) The larger the TTL value, the greater the heartbeat communicationThe lower the frequency.By default, the WordPress Heartbeat API is called 15-30 seconds frequently. By default, WordPress' Heartbeat API is called 15-30 seconds frequently.
    • Adjusting the TTL Setting::
      • Set the TTL to 60 seconds. or longer to reduce the frequency of Heartbeat API requests. A setting of 60 seconds or more is usually recommended to reduce server load.
      • If you find that certain features rely on real-time communication (e.g., draft autosave), you can keep the TTL time short. Otherwise, longer TTL times can be effective in minimizing the impact on the server.
How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  1. Save Settings
    • After completing the settings, click Save Changes button to ensure that the adjustment takes effect.

4. Manually optimizing the Heartbeat API

If you don't want to use the plugin, you can do it manually in the functions.php file to add code to restrict the Heartbeat API:

add_action( 'init', 'disable_heartbeat', 1 );
function disable_heartbeat() {
    wp_deregister_script('heartbeat');
}

With this method, it is possible to manuallyCompletely disable Heartbeat API.

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage
  • Limit the frequency of Heartbeat API calls

If you don't want to disable the Heartbeat API completely, but just want to reduce the frequency of its calls, you can use the following code snippet:

add_action( 'init', 'modify_heartbeat', 1 );
function modify_heartbeat() {
    // Set Heartbeat interval to 60 seconds
    wp_deregister_script('heartbeat');
    wp_register_script('heartbeat', admin_url('admin-ajax.php'), array('jquery'), false, true);
    wp_localize_script('heartbeat', 'heartbeatSettings', array('interval' => 60));
}

This code extends the frequency of Heartbeat API calls from the default 15-30 seconds to 60 seconds. You can adjust the interval value (e.g., 120 seconds).

  • Disable Heartbeat API for backend or frontend only

If you only want to limit or disable Heartbeat API calls for a certain section (e.g. backend or frontend), you can use the following code snippet as needed:

How to optimize admin-ajax.php in WordPress: reduce performance issues caused by high usage

Disable the Heartbeat API in the backend Dashboard::

add_action( 'admin_enqueue_scripts', 'disable_heartbeat_in_dashboard', 1 ); function disable_heartbeat_in_dashboard() { wp_deregister_ script('heartbeat'); }

Disabling the Heartbeat API in the post editor(e.g., disable automatic saving of drafts):

add_action( 'admin_enqueue_scripts', 'disable_heartbeat_in_post_editor', 1 ); function disable_heartbeat_in_post_editor() { global $pagenow; if ( $pagenow ! = 'post.php' && $pagenow ! = 'post-new.php' ) return; wp_deregister_script('heartbeat'); }

Disabling the Heartbeat API in Frontend Pages::

add_action( 'wp_enqueue_scripts', 'disable_heartbeat_in_frontend', 1 ); function disable_heartbeat_in_frontend() { wp_deregister_script(' heartbeat'); }
  • After you have finished adding the code, click the bottom of the page on the Updated documents(Update File) button. Ensure that the changes have been successfully saved and visit your website to test the use of the Heartbeat API.

Further optimization of recommendations:

  • Disable unnecessary Heartbeat API requests: If your site doesn't rely on the Heartbeat API for functionality (e.g., real-time notifications on front-end pages), the LiteSpeed Cache maybe Heartbeat Control Disable Heartbeat calls on the frontend or dashboard in the plugin.
  • Combined with cache optimization: In addition to limiting Heartbeat API calls, you can further optimize your site's performance by leveraging the caching features provided by LiteSpeed Cache (e.g., page caching, database caching, object caching).

summarize

make superior admin-ajax.php The file is vital to keep your WordPress site performing well. It handles all the AJAX requests for dynamic functionality, but if not managed properly, it can lead to overloaded websites and performance degradation. By using tools to diagnose and optimize requests, enabling caching, and limiting the Heartbeat API, you can dramatically reduce the load on admin-ajax.php and improve the speed and stability of your site.


Contact Us
Can't read the article? Contact us for a free answer! Free help for personal, small business sites!
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
Posted by photon fluctuations, retweeted with attribution:https://www.361sale.com/en/21940/

Like (0)
Previous 1 day ago
Next 20 hours ago

Recommended

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

020-2206-9892

QQ咨询:1025174874

E-mail: info@361sale.com

Working hours: Monday to Friday, 9:30-18:30, holidays off

Customer Service