What are potential pitfalls when using PHP as CGI in a web server like Tomcat?

One potential pitfall when using PHP as CGI in a web server like Tomcat is the performance overhead caused by spawning a new PHP process for each request. This can lead to slower response times and increased server resource usage. To mitigate this issue, you can use a PHP FastCGI implementation like PHP-FPM, which allows for persistent PHP processes to handle multiple requests, improving performance.

# Example configuration for PHP-FPM in Apache
<IfModule proxy_fcgi_module>
    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://localhost:9000"
    </FilesMatch>
</IfModule>