Table of contents of the article:
WordPress, recognized as the most popular content management platform (CMS) globally, boasts a wide range of plugins designed to allow users to monitor and quantify the flow of visits to their websites. Despite the popularity of such tools, many plugins are built using PHP and MySQL, two technologies that, despite their ubiquity, can present their own set of efficiency and performance challenges, especially when there is a lot of network traffic.
Inefficiencies of Visit Counters based on PHP and MySQL
Visit counters in WordPress based on PHP and MySQL work by generating hundreds or thousands of PHP threads per second to manage visits and store this information in the database through INSERT or UPDATE operations. When traffic becomes heavy, this process can become problematic, resulting in server overload due to the constant creation of new PHP threads and database congestion.
PHP and MySQL are also not known for their performance in terms of speed and efficiency. Compared to more modern and agile technologies, such as Go and NodeJS, or NoSQL databases, such as REDIS or MongoDB, PHP and MySQL can be less performing, especially when it comes to managing a large number of concurrent requests.
The problem with the Post Views Counter plugin
Among the various WordPress plugins used to monitor site traffic, Post Views Counter is one that unfortunately stands out for its limitations rather than its strengths. Designed for sites with low traffic volume, its operation becomes problematic and inefficient when it has to handle a large number of visitors.
Post Views Counter is based on PHP and MySQL, two technologies that, as we have seen, can suffer in terms of efficiency and speed when faced with high traffic. Consequently, the use of this plugin can lead to server overload and database slowdown, due to the continuous INSERT and UPDATE operations required to record visits.
Making matters worse, Post Views Counter does not interact effectively with server-side caches like Varnish Cache or NGINX FastCGI Cache. In fact, it tends to bypass these caches, causing PHP code to be executed and the database to be accessed for each visit, a behavior that further reduces the site's speed and overall performance.
Given its design and limitations, Post Views Counter turns out to be an unsuitable plugin for sites with high volume of traffic. If used in such contexts, it should be immediately removed and replaced with a more performant and suitable alternative, such as the external services Google Analytics, Matomo or Jetpack. These not only avoid the problems associated with using PHP and MySQL, but also offer a number of additional features for more detailed and useful monitoring of site traffic.
Interaction with Server Side Caches and Consequential Problems
Another emerging issue is the interaction of many WordPress hit counter plugins with server-side caches, such as Varnish Cache or NGINX FastCGI Cache. These plugins tend to bypass these caches via AJAX calls to 'admin-ajax.php', thus defeating the effectiveness of a highly efficient page caching system like Varnish. As a result, every single visit could result in PHP code execution and database access, having a significant negative impact on site speed and overall performance.
admin-ajax.php is a crucial component of WordPress, often used to handle AJAX requests. Before we get into how it works, it's helpful to take a step back and understand what an AJAX call is.
In the context of WordPress,
admin-ajax.php is the file that handles these AJAX calls. When a WordPress plugin or theme needs to perform an AJAX function, the request is sent to
admin-ajax.php, which handles the request and sends a response. This process can be used for a variety of functions, such as uploading new posts, counting visits, updating comments, and many more.
Despite its usefulness,
admin-ajax.php can present problems. One of the most notable is that AJAX calls bypass server-side caches like Varnish Cache or NGINX FastCGI Cache by default. This means that each AJAX request executes PHP code and accesses the database, even if the requested data hasn't changed. This behavior can cause server overload and site slowdown, especially with a high volume of traffic or a large number of AJAX requests.
Also, the fact that
admin-ajax.php both used for both front-end and back-end side requests can lead to performance issues, since all AJAX requests must go through the same trigger point, regardless of their complexity or purpose .
In conclusion, despite being a fundamental component of WordPress,
admin-ajax.php has limitations that can have a significant impact on site performance. It is important to take this into account when developing or choosing a WordPress plugin or theme, and look for solutions that minimize the use of AJAX calls or handle them more efficiently.
Unwanted Side Effects
Issues associated with using PHP and MySQL-based visitor counting plugins can trigger a number of undesirable side effects, including increased server load, server crashes, and subsequent service outages, not to mention inevitable negative impact on the user experience and visibility of the site on search engines. These consequences can be exacerbated in situations of high web traffic, with the need to handle a massive number of requests simultaneously.
One of the most common problems in this situation is the increased load on the server. With an increasing number of requests to handle, PHP and MySQL can find themselves under pressure, having to work harder to manage the flow of data. This can lead to excessive consumption of server resources, making the entire system slower and potentially unstable.
In some cases, server overload can lead to a 500 type error, an HTTP status code indicating a general server failure. In particular, if you are using PHP-FPM (FastCGI Process Manager) to handle PHP requests, saturation of PHP FPM pools can cause a 500 error. This error is usually a sign that the server is struggling to handle the current workload .
Even a server crash is a possible consequence of these issues. In extreme circumstances, the high workload can bring the server to a complete stop, causing site downtime. Not only does this interrupt access to the site, but it can also have repercussions on the site's reputation and user trust.
Alternatives to Visit Counters based on PHP and MySQL
A possible remedy to these problems is to avoid the use of plugins that operate in the manner described above. A commonly employed feature at the theme level is the 'post_views_count()' function. This feature logs each visit to a specific post and updates a counter in the database. Although it may seem useful, it contributes to increase the load on the server and the database.
A more efficient strategy would be to rely on external services such as Google Analytics, Matomo or Jetpack. These services manage the counting of visits on separate servers, thus reducing the load on the website server.
The Potential of Jetpacks
Jetpack, one of the most reputable external services for managing and monitoring WordPress sites, stands out for its ability to handle a huge volume of traffic, peaking at hundreds of thousands of visitors per second without taxing the server hosting the site. But in addition to this amazing traffic management capability, Jetpack also boasts a wide range of features that allow detailed and precise monitoring of visits, making it an extremely useful tool for analyzing user trends and behaviors.
Jetpack Visit Counter functionality
Jetpack's visit counting functionality goes beyond simply providing a total number of visits. On the contrary, it offers a series of detailed statistics, providing a complete picture of site traffic and its trends.
Jetpack allows you to view daily, weekly, monthly and yearly statistics. This allows you to easily monitor traffic trends over time and to identify peak periods or possible decreases in visits. This information can be very useful for optimizing content or marketing strategies, for example choosing the best time to publish new posts or launch new campaigns.
But Jetpack goes further, offering the possibility to analyze visits to individual posts as well. This means that you can have an accurate picture of which contents are performing better, which ones are attracting more visitors and which ones could need improvement. This feature helps you understand which themes or topics are most popular with your visitors, allowing you to tailor your content strategy based on audience preferences.
In addition, Jetpack offers a geographic view of visits, allowing you to see where in the world visitors are coming from. This can be especially useful for targeting content or marketing campaigns towards specific geographic markets.
Visit counters based on PHP and MySQL, while common in WordPress, can cause a variety of problems, especially when there is high web traffic. Relying on external services such as Google Analytics, Matomo or Jetpack can not only solve these problems, but can also provide a number of additional features that improve the efficiency, performance and general management of the website. To ensure a smooth, fast and traffic-handling WordPress website, it is essential to make the right choices in terms of tools and technologies.