0

There is the following issue: I have to detect FastCGI SAPI in order to send off a custom response. For FastCGI it looks like 'Status 404 Not Found' against standard 'HTTP/1.1 404 Not Found'. As far as I know PHP implements FastCGI only as a part of FPM.

So is it right way to detect FastCGI:

     if (preg_match('|fpm|', PHP_SAPI))
         print('FastCGI');
Agent Coop
  • 392
  • 4
  • 12
  • http://stackoverflow.com/questions/609044/how-to-know-for-sure-if-fastcgi-is-being-used-to-run-php-scripts – s.webbandit Feb 26 '13 at 08:31
  • 1
    Are you sure you need to send a custom response? See [this stackoverflow post](http://stackoverflow.com/questions/8828275/still-necessary-to-use-status-404-not-found-for-fcgi) for more info on HTTP vs Status and FCGI – alldayremix Feb 26 '13 at 08:35
  • Yeah, probably that's what I need. – Agent Coop Feb 26 '13 at 09:22

1 Answers1

0

I would use

if (PHP_SAPI === 'fpm-fcgi') {
  print 'FastCGI';
}

If you wanted to detect any cgi/fast-cgi environment I would use

if (preg_match('|cgi|', PHP_SAPI)) {
  print('FastCGI');
}

I avoid regexes just because it tends to make life easier for the person coming after me in three years trying to read the code tracking down some unrelated bug.