Fixes #3938. Do more error checking.
Properly test if FCGI is calling or are being triggered from shell. Normally Fixes #3361
Properly test if FCGI is calling or are being triggered from shell. Normally Fixes #3361