TIL: PHP IIS 8kb Request Limit?
Today, at $dayjob, I was called into a remote debugging session. For some reason the DokuWiki install at a customer failed to save long pages. Instead of saving, the editor just reloaded and showed the previous state again. No errors in DokuWiki and none to be found in the various places PHP and the web server used for logging.
Now this was on a Windows machine with IIS as the web server using PHP via CGI. Not my recommended setup but somewhat common in business contexts. The weird thing was, when the customer switched back to an older release of PHP it worked again.
I created a simple test script to make sure it was not DokuWiki's fault and sure enough: the same issue there. Posting a “hello” worked, posting a 50kb test text resulted in a zero byte request body.
Using another quick script, we found out that the exact limit was 8192 bytes - 8kB. I checked all the usual suspects: post size, any kind of limit in IIS. Nothing.
I had to leave the session for another meeting and was still puzzled when I got back. But while I was still wondering what to do next, a happy mail from the customer arrived - they had figured it out. They went to download and install PHP again and this time it worked.
Why? They picked the correct download this time!
Let me quote the PHP Windows Download page:
NTS builds are for single-threaded use cases, typically PHP running via FastCGI or on the CLI. TS builds support multithreaded SAPIs and are intended for PHP loaded as a web server module. So, if you want to use PHP as FastCGI with IIS, use the Non-Thread Safe (NTS) builds of PHP, or if you want to use the Apache HTTP Server, use the Thread Safe (TS) builds of PHP.
So yeah. They had accidentally used the thread-safe build in CGI mode.
I have never seen this behavior before and couldn't find anything about it on the Internet. I always expected the wrong version simply wouldn't work. But apparently the bugs are more subtle.
So here is today's learning:
When your PHP on IIS is dropping request bodies larger than 8kb, you probably downloaded the wrong PHP version. Use the non-thread-safe version with IIS!