What are the differences in overhead between using mod_php and PHP as CGI?

When using mod_php, PHP scripts are executed within the Apache web server process, resulting in lower overhead and faster performance compared to running PHP as CGI, where each script is executed in a separate process. However, using mod_php can potentially pose security risks as it runs with the same privileges as the web server. On the other hand, running PHP as CGI allows for better isolation and security but incurs higher overhead due to the need to spawn separate processes for each request.

// Example of running PHP as CGI
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi

// Example of PHP script running as CGI
#!/usr/bin/php-cgi
<?php
echo "Hello, CGI!";
?>