Thanks for sheding a lot of light on this.

As for error handling in the REST code I found that the PUT data must be read or the script will wait until timeout. Adding something like the following will make sure that any error immediately handles the input stream:

set_error_handler(function() {
@fclose(@fopen('php://input', 'rb'));
}, 0xFFFF);

Of course the error handler would need to be be a bit more sophisticated in a real world application, but I hope you all get the picture.