(Last Updated On: )

At Advantech, we have several cloud hosted VPS’s that we administer to host sites and applications on. Our VPS’s are currently all Windows Servers – why you ask? Because we develop .NET applications that require IIS and Windows to run. But we also host websites, of which we use WordPress as our preferred CMS. Finding information about hosting settings and tuning for IIS is a little harder to come by than it is for NGinx or Apache servers.

One of our servers has around 10 WordPress websites hosted, 16Gb memory, 120Gb SSD drives. All the specs are there, but the WordPress sites were still not firing quickly, it was always a “slow server” response I’d get from GTMetrix or Google PageSpeed Insights. Eventually, I decided I really need to spend some time investigating why these sites were so slow. And it wasn’t all sites that were slow, some were lightning fast and others were taking 10+ seconds to even start rendering.

Same server, usually same theme, same cache plugins.

Turn on Debugging for WordPress

Within the wp-config.php file, add in the following directives to turn on Debugging:

// Enable WP_DEBUG mode
define('WP_DEBUG', true);

// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Disable display of errors and warnings - don't want them on the screen
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

As you can see, it’s simple directives that can be added to the wp-config.php file in the root of your WordPress installation. By turning debugging on, you will see errors appear in the debug.log file that is placed in the root of the /wp-content directory.

Viewing the debug.log File

My handy tip is get yourself a copy of “Tail for Windows“. If you have ever administered a unix platform, you would have used the tail command. It’s a great tool to see changes to a file in realtime without having to refresh the file.

WordPress Debug Findings

One error that was constantly appearing is the following:

PHP Warning:  Unknown: open(C:\Windows\temp\sess_o8ol1t1eo10ft14ses8ffq9135, O_RDWR) 
failed: Invalid argument (22) in Unknown on line 0

Why was it trying to put the temp files in this directory and why wasn’t this directory accessible since it’s a general temp directory?

My possible solutions:

  1. Change the permissions of C:\Windows\temp to give IIS_IUSRS Modify permissions – I attempted this but there were *a lot* of temp files in this directory and it was taking ages.
  2. Look at the php.ini file to see what the session.save_path setting was.

PHP INI File Settings

The php.ini file didn’t have a setting for session.save_path in the file – it was commented out. How could it still be writing to to C:\Windows\temp if this setting was missing? I added in the the setting and I created a temp directory called C:\temp\phpsession to be the place to store the session files.

I restarted the Website I was debugging. Sessions were still attempting to save to C:\Windows\temp ?? WHY???

Scroll Down – there is a section called [WebPIChanges]

And there it was –

session.save_path=C:\Windows\temp *****
extension_dir="C:\Program Files (x86)\PHP\v5.6\ext\"

I changed this setting to C:\temp\phpsession – My Custom directory that I created to store sessions. Make sure IIS_IUSRS has permissions to write to this directory.

Restarted the Website I was debugging. And it was like a light bulb moment for this website, it was loading fast, like a *normal* site should!

* Such a small change for such a big gain *


Don’t forget to turn your debugging off again in wp-config.php!