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.