PHPology is a collective of highly skilled, award winning, web gurus.
Contact Raj on 07985 467 213 or email [email protected]

PHP sessions and garbage collection on Windows 2008

This week one of our Windows 2008 servers was slowly grinding to a halt and after 2 days of running tests (via Rackspace) various options were thrown to work out what was going on.

A hard disk scan was arranged, RAM checks, faults in network issues, etc, etc.

Then the engineer at Rackspace pointed out that within the WindowsTemp folder, there was over 1million session files in that folder and COULD have potentially be causing an issue.

First thing that came into my mind was, why was PHP Garbage Collection not working, even though by default it was set to 1% chance of clearance, it should have certainly kicked in from 2011.

After spending 2/3hours deleting the files, Google search commenced, various blogs went by and to my mind I thought "its surely a permissions problem against the Temp folder", which PHP could read/write to but not delete.

Rather than playing with the Windows Temp folder, I updated the PHP.ini file and moved the sessions tmp folder into the main PHP folder itself within Program Files.

Assigned the usual permissions, mainly IIS_IUSR, with full control and refreshed my website. Received an error “permission denied”. Baffled at this point to why it would fail, I set the usual permissions I would to a public facing website that needs to write to a folder.
More searching occurred and just randomly reading a forum thread, someone mentioned, “Assign the Users” user also with “Full permissions”. I noticed that the Windows Temp folder did have this permission BUT no read/write/full control was checked.

Now my sessions are appearing in its new location, I also took the advantage of moving the PHP error log out of Windows Temp also and that seems to be populating also (not a good thing).

Prior to leaving late at night, I did have 3000 session files in that folder but come 8:30am and reviewing that folder again, it was 140 odd files.

BASICALLY GARBAGE COLLECTION WAS NOW WORKING :-)

Now I am waiting for the load to increase on the server to see if all this has basically solved my load issue problem.