If you are using WooCommerce with lots of products, you’ll have noticed it slows down significantly. There is some pretty bad code inside WooCommerce which iterates through every single one of your products in PHP to build category lists – these operations take milliseconds in mysql but tens or hundreds of seconds in PHP depending on how many products you have in your store.
HHVM – Hip Hop Virtual Machine – was built by Facebook to change PHP into a compiled language rather than an interpreted language. Specifically for these terrible types of language patterns, HHVM will give you significant speed boosts. (Better would be if WooCommerce could get their code sorted out)
Installing HHVM
https://github.com/facebook/hhvm/wiki/Prebuilt-packages-on-Ubuntu-14.04
# installs add-apt-repository sudo apt-get install software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449 sudo add-apt-repository 'deb http://dl.hhvm.com/ubuntu trusty main' sudo apt-get update sudo apt-get install hhvm
That’s HHVM installed, now to get it running:
hhvm --mode daemon -vServer.Type=fastcgi -vServer.Port=9000
If you’re using Nginx, all you need to do is stop the PHP5-FPM service and ensure you’re sending traffic over to port 9000.
With a client’s site – she has 105,000 products in WooCommerce – previously she was getting a response from /store/ (a page that really should be far quicker but isn’t because of the product/category counts which occur) in 185 seconds. With HHVM that same page returns in 10 seconds. Still not ideal, but at least NOW when I combine this with a caching system it’ll work for all users.
There is some additional info here about getting it set up with Nginx
Ensuring HHVM stays up and Configuring CRON
It’s new and shiny and might break easily so you should set up a cron job. With some testing, I found that you don’t need to check if it’s running – just try to run it. If it’s already running, it sorts itself out. You should also take this opportunity to switch from PHP-FPM to HHVM for your cron jobs too (if you’re using cron for your cron jobs that is)
crontab -e
The following two lines at the end will do it.
*/1 * * * * hhvm /var/www/insertyourwebfolderhere/wp-cron.php */1 * * * * hhvm --mode daemon -vServer.Type=fastcgi -vServer.Port=9000
Setting all of this up the easy way
If you don’t want to mess about with linux and you’d rather have someone do this for you, WP Engine are the best in the business. They have nginx set up, they have high capacity, failover based systems and they were one of the first to set WordPress up with HHVM. They’re affordable too – you can find out more about WP Engine here.
- My WordPress performance plugins and server stack have moved - July 31, 2016
- Price Comparison Pro 1.2 Released - July 5, 2016
- How to run backups on huge WordPress websites without your website being brought offline - February 4, 2016
March 11, 2015 @ 6:22 pm
Hi
id be interested in seeing what the Woocommerce bits are that cause this issue and if we could put a plugin together to overwrite these functions to limit the damage it can do in terms of times taken to process stuff.
either that or is it possible to move some of these php functions out into asyn to make them work without affecting the front of the site?
Im looking at using woocommerce for some affiliate sites now and would be very interested in your thoughts.
Page bookmarked for future ref also.!! thanks for the github repo for setup.
March 11, 2015 @ 8:35 pm
Hi – I went through quite a bit of working optimising the underlying SQL queries until I then discovered you can simply remove them – they’re not required at all as all they’re doing is counting products in each category – that happens EVERY page load and updates the database – very inefficient.
Anyway – to stop this abominable code from running and seriously speed up your large woocommerce sites, add this line to your functions.php file:
remove_action( ‘woocommerce_before_shop_loop’, ‘woocommerce_result_count’, 20 );
May 12, 2015 @ 10:30 am
Very good post. Well done
May 14, 2015 @ 11:37 am
Hello,
Thanks for sharing. Which file exactly has to be edited.
Thank you.
May 14, 2015 @ 12:50 pm
You don’t need to edit a file. Run the first commands from the shell – SSH – log in using Putty or similar. As for the crontab file, you just run the crontab -e command from the shell and it will let you add the cron job.
May 15, 2016 @ 8:13 pm
Hello,
The improvement in your client’s site page load time from 185 Seconds to 10 Seconds is great! Did this happen “just” by the installation of HHVM or you had to make some other optimizations?
Eager to hear from you.
Thanks!
July 4, 2016 @ 4:18 pm
In that case, yes, it was HHVM. For them, they were using simple affiliate products (not variable products). WooCommerce was fetching EVERYTHING and then parsing it all using PHP. I didn’t speed up the database bit for them but the HHVM speeded up the PHP parsing.
October 18, 2016 @ 6:57 am
can you give me the site where more then 100000 SKU are there using Woo Commerce. that would be great help
February 19, 2017 @ 6:05 pm
http://www.foundthru.com
February 7, 2017 @ 9:14 am
11 seconds is still slow…
February 19, 2017 @ 6:00 pm
I agree – that’s why I’ve built the Rocket Stack and Scalability Pro – both of these combined, along with avoiding some bad plugins, ensures sub-second speed everywhere
April 1, 2017 @ 8:40 am
11 second is still very low in today’s world. I am planning to start an ecommerce website with over 20,000+ products and over 300,000 pages.
Do you still recommend woocommerce for such big website?
April 4, 2017 @ 7:45 am
Yes sure – there are understandable reasons why people think performance is poor with wordpress, but really it’s just a matter of eliminating the poor code or rewriting it.
My plugin Scalability Pro does that.