PGP vs Perl CGI
How Perl CGI works
- User's browser makes an HTTP request to server for the CGI page.
- Depending on the configuration of the server, it will figure out the request is not static content but a request to execute a program based on the directory and/or the file extension.
- The server executes Perl, passing the name of the script to be executed,and setting up a series of environment variables related to the HTTP request (more on that later). If the request was a POST form submission, the form data will be sent to stdin.
- Perl reads in and compiles the specified program in memory.
- Perl executes the program. The stdout of the script is captured by the web server.
- The script's output is sent back, with header information, to the browser.
How PHP works
- User's browser makes an HTTP request to server for the CGI page.
- Depending on the configuration of the server, it will figure out the request is not static content but a request to evaluate PHP code in an HTML document based on the directory and/or the file extension.
- The module that evaluates PHP code, already dynamically linked into apache and in memory, is called to evaluate the page.
- The PHP module is fed in the contents of the page, and interprets it. The stdout of the script is fed back t apache.
- The PHP module's output is sent back, with header information, to the browser.
Advantages of PHP over Perl CGI
- No need to launch a separate process (very expensive) and load the interpreter- it's already in memory.
- As an apache module, it has access to the apache internal structures and hooks (for authentication, authority, redirection,..).
- With Perl, all the "static" fragments of HTML output must be output via print statements that evaluate the strings. With PHP, the static fragments of HTML outside of a PHP block are just ouptut without interpretation.
- While Perl's CPAN library provides any functionality you could imagine, many of the popular ones are built-in to PHP, like sessions, database access, XML, image manipulation, LDAP, mail, etc.
- PHP looks more like C than Perl does (because everything is a function, and because of Perl's reliance on punctuation), it may be easier for some programmers to learn and debug.
Other alternatives
- FastCGI http://www.fastcgi.com/
FastCGI programs are persistent CGI programs. When a request comes into the web server, the server connects to your already-running FastCGI program via sockets, passing the input to it and getting output from it through that socket. When your FastCGI program is done servicing that request, it closes the socket connection and waits for another. Since no processes are being started up, and your program gets compiled into memory on the first request, it can be much faster than CGI. They can also run on a different server than the web server itself. You can also run a pool of them to handle multiple concurrent connections. However, since your program never exits, you have to be much more careful about using uninitialized variables and "putting away your toys when you're done with them".
- mod_perl http://perl.apache.org/guide/
mod_perl works much like PHP- an apache module, already loaded in memory, compiles the perl code and executes it. It saves the time firing up a new process each time. It also uses something called code caching, where modules and scripts are loaded and compiled only once, and for the rest of the server's life they are served from the cache.
- Alternative PHP Cache http://apc.communityconnect.com
Same kind of code cacheing as mod_perl, but for PHP.
- afterBURNER http://bwcache.bware.it
Another implementation of code cacheing.