How to fix caching issue with PHPSESSID and Easy Digital Downloads

Easy Digital Downloads (EDD) plays a vital part in our business. It enables us to easily build and sell WordPress plugins. It’s lightweight and we always recommend it over WooCommerce if you’re dealing solely with digital products. The developers of EDD are also excellent and are continuously improving the solution. 

However, as with any WordPress product, there are sometimes problems. Today I want to provide a little insight into how we resolved a complicated caching issue with PHPSESSID and Easy Digital Downloads a few years ago. 

What is PHPSESSID?

By default, Easy Digital Downloads uses PHP sessions as they are typically more performance-friendly than database-driven session handling and help avoid issues with some object caching plugins and their shortcomings with the transient option types (source). 

PHPSESSID is the name of the cookie that is downloaded to your browser when a new PHP session is started. PHP sessions can also be stored by URLs, but in this instance, it’s a cookie implementation. This is generally a more secure approach. 

You can see the PHPSESSID cookie in Chrome DevTools under “Application → Storage → Cookies.” The random value is generated by the server when you first visit a site. 

PHPSESSID cookie in Chrome
PHPSESSID cookie in Chrome

PHPSESSID caching issue

A couple of years ago, we ran into a problem with Easy Digital Downloads. Customers started to see other items in their shopping cart, even though they hadn’t added them. Ironically, this was probably happening from the very beginning, but we only noticed it once traffic to our sites started increasing. 

I knew right off the bat it was a caching issue. I could open two different browsers in incognito mode and get the same PHPSESSID value. That should never happen, period.

Uh oh Meme (Image source: imgflip)
Uh oh Meme (Image source: imgflip)

How to fix PHPSESSID caching issue

Below are a few things I tried first when troubleshooting the caching issue with PHPSESSID. 

  • I confirmed that the checkout pages weren’t being cached by our hosting provider (Kinsta). They weren’t, because they automatically BYPASS cache for the pages where the edd_items_in_cart cookie is found. 
  • I added a query string ?nocache=true on the “Buy Now” buttons to make sure nothing was ever cached on the checkout page.
  • I temporarily tried disabling PHP sessions to resort back to WP_Session and the wp_options table (source). But this didn’t make any difference. 
  • I added the following EDD filter to force only one thing to be in the shopping cart checkout at a time. This works great, but it didn’t fix the original caching issue.
add_filter( 'edd_pre_add_to_cart_contents', '__return_false' );

You also can’t just BYPASS cache for any pages that contain PHPSESSID, because that would effectively BYPASS cache for your entire site. Or, in other words, destroy the performance of your site in one fell swoop.

I tested EDD on a local development site, and not to my surprise; the problem wasn’t happening. But this is because I didn’t have any caching solution on my local site.

After my troubleshooting was going nowhere, I decided to reach back out to Kinsta. I provided all the details regarding things I had tried. They were able to replicate the issue on their end and escalated it to their sysadmin team. And voila! It turns out it was my Nginx config. There is actually a way not to cache the PHP session itself. After the sysadmin tweaked my Nginx config, the problem vanished.

If you’re curious, I’m now also using Cloudflare APO in front of Kinsta’s servers. However, I wasn’t when the problem started happening. If you’re using Cloudflare, you still need to apply the fix with your hosting provider (origin server).

Cloudflare APO supports Easy Digital Downloads out of the box. They automatically BYPASS cache for the pages where the edd_items_in_cart cookie is found. 

Summary

If you’re experiencing any issues with PHPSESSID and caching, save yourself some time and simply reach out to your hosting provider. Feel free to provide them the info above to get it resolved quickly. 

This experience also made me once again appreciate how well Kinsta handled the situation. Their support team always goes above and beyond. 

If you ever experience a similar issue, I hope this helps save you some time!

author bio
Brian Jackson

I craft actionable content and develop performance-driven WordPress plugins. Connect on X, subscribe to my newsletter (once a month), or buy me coffee.

Leave a Comment