Check surprise flags after I/O

Summary: Check surprise flags immediately after waiting for I/O and avoid
execution of any PHP code if the request timeout (or other error
condition) has occurred.

Reviewed By: @jdelong

Differential Revision: D1396843