Trying to run some php scripts on a new shared server account, the scripts constantly hang and timeout with no error messages. Only when running the scripts in Chrome with the web developer console up did I get a hint of what was going on: “net::ERR_INCOMPLETE_CHUNKED_ENCODING” is what it would say.
Fiddler2 was slightly more specific:
Fiddler.Network.ProtocolViolation - [#165] Transfer-Encoding: Chunked response did not terminate with a proper zero-size chunk.
…and:
Fiddler.Network.ProtocolViolation - [#165] [HTTPLint #M012] The HTTP Chunked response body was incomplete; most likely lacking the final 0-size chunk.
I made a test script to demonstrate the problem. All it did was sleep() for a random 20-60 seconds, then display a random string. Ten iterations by default.
But the helpdesk at this hosting provider kept insisting that it had something to do with a hard 60 second timeout in the php environment, which I knew was hogwash. So I put together a second test script that used Ajax to call another script multiple times in succession. Again, it was bone simple, just a sleep() for a random time between 40 and 55 seconds, then generate and display a short random string of characters.
So it could never take more than 60 seconds to execute. But it still kept failing, albeit with “net::ERR_EMPTY_RESPONSE” for the xhr call in the Chrome console instead of “net::ERR_INCOMPLETE_CHUNKED_ENCODING”.
When I showed this to them, they actually admitted there was a problem, which felt like a victory. But it was short-lived. The very next day they came back and said, so sorry, they couldn’t figure out what was causing this, nothing they can do, have I considered upgrading to a vps?
I have become somewhat obsessed. I want to know what the hell is causing this.
The code for the first test script I wrote is here: Test_Script - Pastebin.com. You can go to this page: http://www.scripttest1.cu.cc/test_script.php to see for yourself what happens when it is run on this server.
The code for the second test script is here: Test_Script_2 - Pastebin.com, the javascript here: Test_2_js - Pastebin.com, and the script it calls via ajax, here: Test_Script_2a - Pastebin.com. Go here: http://www.scripttest1.cu.cc/test_script_2.php?longorshort=long to see it in action. Unlike with the first script, the error it generates is “empty response”. But I assume the two are related.
Both these scripts work fine on both another shared server, and a vps with LAMP, to which I have access. They also work on this server, for a while, before they fail. The first test script usually gets through a few iterations before it dies. The second one, with the Ajax, will sometimes run right through to completion if the “longorshort” is set to “short”.
Also, the first test script works flawlessly from the command line. The second one of course won’t work right in that environment.
The server runs PHP Version 5.4.44 and Apache Version 2.4.16 under Linux.
Google has not been my friend. I posted to Stackoverflow and got exactly 5 (five) views, zero responses.
Can anyone here at least toss me a clue? Or failing that, point me to an alternative to Stackoverflow where they might actually answer my question?