PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Website overwhelmed with calls to currency switcher - causing outage

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

I've been using WOOCS/Fox for years. I updated to Version 2.5.6 on 10/18. Since then, the site has been up and down almost constantly, and when it is up, it is slow, it is taking an extraordinarily long time to render a WooCommerce page including a standard filter sort. or the product detail page. I've been working with WooCommerce directly as well as my hosting panel provider to determine the cause. This is a large site with nearly 3,000 items. https://collectorstudio.com/

Up until I installed the new version update, the site has been very fast. We have tried everything since then to fix the problem, as whenever I turn on the site, the php-fpm request threads fill up quickly and the site crashes. We've ruled out the server, as it has plenty of resources. We've blocked most bot traffic; I've deleted the caching etc., cleared WooCommerce product attribute tables, etc.

After much consideration, I've temporarily deactivated the plugin to test the theory. The site is back to"operational" (without Fox), but I have to have Fox running as the site is based in Canada.

The php-fpm children are not filling up. It is definitely related to something in the 2.5.6 version release.

I'm attaching a log that we've been generating that traps this traffic. Here is the comment from Plesk:

Furthermore, in the slow PHP logs i.e. /var/www/vhosts/collectorstudio.com/logs/slow.log, I see such heavy requests keeps coming repeatedly:
 
woocommerce-currency-switcher
init_geo_currency()
geolocate_ip()
wp_safe_remote_get()
curl_exec()

From my research, I see these requests does external HTTP request so that they can slow down the php workers process. I copied the /var/www/vhosts/collectorstudio.com/logs/slow.log to /var/www/vhosts/collectorstudio.com/httpdocs/ so that you can download and share with the Woocommerce team to further review from their end and see if this is expected result.

Here is a zipped copy of the slow file zipped. - https://collectorstudio.com/slow.zip

Please help me as soon as possible as this is a very active site. Thank you very much in advance.

And yes, I'm running the pro version.

 

 

Hello

Thank you for the detailed report and for sharing the slow log, it helped a lot.

I went through the whole log: 17,011 slow request records from Oct 28 06:31 to Oct 29 03:23, about 15 per minute with peaks of 48 per minute. FOX appears in 283 of them, that is 1.7%. The external geolocation requests (curl_exec) come from two places:

1. WooCommerce itself, 387 records. The chain is geolocation_ajax_redirect > wc_get_customer_default_location > geolocate_ip > get_external_ip_address. This happens because in WooCommerce > Settings > General the option"Default customer location" is set to"Geolocate (with page caching support)". With this option WooCommerce asks an external service for every new visitor and also redirects every guest page to a URL with ?v=..., which doubles the number of requests.

2. FOX, 74 records, when it detects the visitor country for the GeoIP rules.

Both use the same WooCommerce geolocation. When the MaxMind database is not connected, WooCommerce asks external web services, and every such request keeps a PHP worker busy for up to several seconds. With many bots coming from different IP addresses the PHP-FPM pool fills up.

The rest of the log is the general load of the site: database queries (mysqli_query is the most frequent top entry), Ninja Forms, the Enfold theme layout builder. Most admin-ajax.php requests in the log are still loading WordPress when they are caught, before any plugin handler starts, which is a sign of an overloaded server rather than one slow function.

Here is what I suggest, step by step:

1. WooCommerce > Settings > General > Default customer location: set it to"Geolocate" (without page caching support), or to"Shop base address" if you do not need the customer location for taxes.

2. Connect the MaxMind database, then the country is detected locally on your server, without any external requests. Create a free account at https://www.maxmind.com/en/geolite2/signup, generate a license key in your MaxMind account, then paste it in WooCommerce > Settings > Integration > MaxMind Geolocation and save. WooCommerce will download the database and keep it updated.

3. In FOX settings, Options tab, please change"Currency storage" from Transient to"FOX Session". With Transient storage the plugin writes visitor data into the wp_options table for every visitor IP, and with heavy bot traffic this table grows.

4. Optionally, you can apply a small change in the FOX code by hand, so the visitor country is detected only once per visit and not on every page view. Please make a backup copy of the file first. Open wp-content/plugins/woocommerce-currency-switcher/classes/woocs.php and find (around line 1111):

$pd = WC_Geolocation::geolocate_ip();
$this->storage->set_val( 'woocs_user_country', $pd['country'] );

Replace these two lines with:

		// The visitor country does not change during a visit, so geolocate only once
		$country = $this->storage->get_val( 'woocs_user_country' );
		if ( empty( $country ) ) {
			$pd      = WC_Geolocation::geolocate_ip();
			$country = isset( $pd['country'] ) ? $pd['country'] : '';
			$this->storage->set_val( 'woocs_user_country', $country );
		}
		$pd = array( 'country' => $country );

 

5. Please run this query in phpMyAdmin (change wp_ if your table prefix is different) and send me the number:

SELECT COUNT(*) FROM wp_options WHERE option_name REGEXP '^_transient_[0-9a-f]{23}$';

After steps 1-3 please activate FOX again and watch the PHP-FPM pool. If it still fills up, send me a fresh slow log from the period when FOX is active and I will check it again.

Best regards,
Alex

 

p.s. Place please actual (NOT EXPIRED) purchase code of the plugin into the private area of the ticket:
https://share.pluginus.net/image/i20230222134241.png
https://share.pluginus.net/image/i20230222134615.png
https://share.pluginus.net/image/i20230222134511.png

Thank you, Alex for your response.

Answers in red

I went through the whole log: 17,011 slow request records from Oct 28 06:31 to Oct 29 03:23, about 15 per minute with peaks of 48 per minute. FOX appears in 283 of them, that is 1.7%. The external geolocation requests (curl_exec) come from two places:

  1. WooCommerce itself, 387 records. The chain is geolocation_ajax_redirect > wc_get_customer_default_location > geolocate_ip > get_external_ip_address. This happens because in WooCommerce > Settings > General the option"Default customer location" is set to"Geolocate (with page caching support)". With this option WooCommerce asks an external service for every new visitor and also redirects every guest page to a URL with ?v=..., which doubles the number of requests.
  2. FOX, 74 records, when it detects the visitor country for the GeoIP rules.

I've changed to Shop country/region. While my client is in Canada, their cart is set to not check out, but able to trigger three different currency prices. There is no money changing hand or a checkout.

Both use the same WooCommerce geolocation. When the MaxMind database is not connected, WooCommerce asks external web services, and every such request keeps a PHP worker busy for up to several seconds. With many bots coming from different IP addresses the PHP-FPM pool fills up.

The rest of the log is the general load of the site: database queries (mysqli_query is the most frequent top entry), Ninja Forms, the Enfold theme layout builder. Most admin-ajax.php requests in the log are still loading WordPress when they are caught, before any plugin handler starts, which is a sign of an overloaded server rather than one slow function.

The server is not overloaded according to my AWS resources.

Here is what I suggest, step by step:

If I have the default customer location set to Shop country /region as I don't anything related to geolocation, do I need to do the maxmind procedure? and these steps below?

  1. WooCommerce > Settings > General > Default customer location: set it to"Geolocate" (without page caching support), or to"Shop base address" if you do not need the customer location for taxes.
  2. Connect the MaxMind database, then the country is detected locally on your server, without any external requests. Create a free account at https://www.maxmind.com/en/geolite2/signup, generate a license key in your MaxMind account, then paste it in WooCommerce > Settings > Integration > MaxMind Geolocation and save. WooCommerce will download the database and keep it updated.
  3. In FOX settings, Options tab, please change"Currency storage" from Transient to"FOX Session". With Transient storage the plugin writes visitor data into the wp_options table for every visitor IP, and with heavy bot traffic this table grows.
  4. Optionally, you can apply a small change in the FOX code by hand, so the visitor country is detected only once per visit and not on every page view. Please make a backup copy of the file first. Open wp-content/plugins/woocommerce-currency-switcher/classes/woocs.php and find (around line 1111):

$pd = WC_Geolocation::geolocate_ip();$this->storage->set_val( 'woocs_user_country', $pd['country'] );

Replace these two lines with:

// The visitor country does not change during a visit, so geolocate only once                $country = $this->storage->get_val( 'woocs_user_country' );               if ( empty( $country ) ) {                       $pd      = WC_Geolocation::geolocate_ip();                       $country = isset( $pd['country'] ) ? $pd['country'] : '';                       $this->storage->set_val( 'woocs_user_country', $country );               }               $pd = array( 'country' => $country );

 

  1. Please run this query in phpMyAdmin (change wp_ if your table prefix is different) and send me the number:

SELECT COUNT(*) FROM wp_options WHERE option_name REGEXP '^_transient_[0-9a-f]{23}$';

After steps 1-3 please activate FOX again and watch the PHP-FPM pool. If it still fills up, send me a fresh slow log from the period when FOX is active and I will check it again.

 

 

 

Hello

Thank you for the answers, now the picture is clear.

Shop country/region is a good choice for your catalog. It stops the lookups WooCommerce made on its own, and the ?v=... redirects of guest pages.

Why the server looks idle while the site is down

PHP-FPM keeps a fixed pool of PHP workers. Their number is limited by pm.max_children in the pool settings (in Plesk: Domains > collectorstudio.com > PHP Settings). Each worker serves one request at a time, from start to finish, and becomes free only when that request ends. When every worker is busy, new requests wait in a queue in front of the pool, and once that queue is full, visitors get slow pages and then 502/504 errors.

When WooCommerce has no local geolocation database, WC_Geolocation::geolocate_ip() asks external web services (ipinfo.io and api.country.is in WooCommerce 11.1) for the visitor country, with a 2 second timeout for each service it tries. The answer is cached for one day per IP address, so a returning visitor costs nothing, but every new IP address costs one or two external HTTP requests.

While a worker waits for that answer, it does almost nothing. It uses no CPU and very little memory, and that is why AWS shows a quiet server: CPU and RAM graphs measure work, and a waiting worker does none. But the worker is still taken. When bots arrive from hundreds of different addresses, the workers end up waiting on geolocation services instead of serving pages, the pool runs out, and the site goes down while CPU and memory still look normal. The pool is the bottleneck here, not the server hardware.

You can confirm it in the PHP-FPM error log for the site (in Plesk usually /var/log/plesk-phpXX-fpm/error.log, where XX is your PHP version). Look for lines like"server reached pm.max_children setting". If the PHP-FPM status page is enabled, the"max children reached" counter and the"listen queue" value show the same thing.

Raising pm.max_children does not fix this. It only adds more workers that wait. The fix is to remove the waiting, which is what the options below do.

Does FOX still geolocate when WooCommerce geolocation is off?

Yes. The"Default customer location" setting controls only WooCommerce's own geolocation. FOX calls the same WooCommerce function directly, on page views and on its AJAX price refresh, to serve the GeoIP rules, and the FOX settings have no switch for this. So with Shop country/region, FOX keeps making the lookups.

There are three ways to handle it. Pick one.

Option 1. Keep geolocation, but do it on your own server

Choose this if you want the GeoIP rules to work, for example so visitors from the US see USD on their first visit.
1. Create a free MaxMind account at https://www.maxmind.com/en/geolite2/signup and generate a license key.
2. Paste the key in WooCommerce > Settings > Integration > MaxMind Geolocation and save. WooCommerce downloads the GeoLite2 database and keeps it updated.
If the site runs behind Cloudflare with IP Geolocation enabled, WooCommerce reads the country from the CF-IPCountry header first and skips the external lookup.

Option 2. Turn off geolocation for FOX only

Choose this if another plugin on the site may still need the visitor country. Create the folder wp-content/mu-plugins if it does not exist, and put a file named fox-disable-geoip.php into it:

<?php
/**
 * Plugin Name: FOX - skip GeoIP lookups
 * Description: Stops geolocation lookups made by FOX only; WooCommerce and other plugins keep their geolocation.
 */
add_filter( 'woocommerce_geolocate_ip', function ( $country ) {
	// Return an empty country only when the call comes from FOX (class WOOCS)
	foreach ( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 ) as $frame ) {
		if ( isset( $frame['class'] ) && 'WOOCS' === $frame['class'] ) {
			return '';
		}
	}
	return $country;
} );

Files in mu-plugins load automatically, there is nothing to activate. FOX stops asking for the country, and everything else keeps working as before. The FOX GeoIP rules will no longer switch the currency by country, so visitors choose the currency in the switcher.

Option 3. Turn off geolocation for the whole site

This is the simplest if nothing on the site needs the visitor country. Use the same folder, with a file named disable-geoip.php:

<?php
/**
 * Plugin Name: Disable GeoIP lookups
 * Description: Stops all WooCommerce geolocation lookups, no external requests are made.
 */
add_filter( 'woocommerce_geolocate_ip', function () {
	// An empty string (not false) makes WC_Geolocation::geolocate_ip() return immediately with no country
	return '';
} );

After that, neither WooCommerce, nor FOX, nor any other plugin that relies on WooCommerce geolocation makes an external request. If"Default customer location" is ever set to"Geolocate", WooCommerce will use the shop base address instead, and the FOX GeoIP rules will stop working.

From what you described, option 3 is enough for your site (or option 2, if you are not sure about the other plugins), and you do not need MaxMind. Neither option needs the code change from my step 4. If you already applied it, it does no harm.

Two things from my previous message are still worth doing:
1. In FOX settings, Options tab, change"Currency storage" from Transient to"FOX Session". With Transient storage, every visitor IP gets its own rows in wp_options.
2. Run the query from step 5 and send me the number. It shows how much the wp_options table has grown.

Then activate FOX again and watch the PHP-FPM pool. If it still fills up, send me a fresh slow log from the period when FOX is active, and I will check it again.

Best regards,
Alex