Speeding Up Perl Scripts With SpeedyCGI/PersistentPerl On Debian Etch
Speeding Up Perl Scripts With SpeedyCGI/PersistentPerl On Debian EtchVersion 1.0 This tutorial shows how to install and use SpeedyCGI (also known as PersistentPerl) on a Debian Etch system. SpeedyCGI is a way to run Perl scripts persistently, which can make them run much more quickly. It keeps the Perl interpreter running, and during subsequent runs, this interpreter is used to handle new executions instead of starting a new Perl interpreter each time. This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!
1 Preliminary NoteI have tested this on a Debian Etch system (with Apache2 installed) with a virtual host www.example.com (document root: /var/www/web1/web) which is configured to run Perl scripts in the /var/www/web1/cgi-bin directory. The paths used here might differ from your setup, so adjust them where appropriate. In the following I will show you three different ways of using SpeedyCGI for your Perl scripts.
2 Installing SpeedyCGITo install SpeedyCGI together with the SpeedyCGI Apache2 module, we simply run: apt-get install libapache2-mod-speedycgi speedy-cgi-perl and restart Apache afterwards: /etc/init.d/apache2 force-reload
3 Using SpeedyCGIFirst we create a normal "Hello World!" Perl script to see if Perl is working. At the end of the script, we use some special code that is executed only if SpeedyCGI is used. This helps us to determine when we are in "SpeedyCGI mode" and when in normal "Perl mode". I create the script in my cgi-bin directory, /var/www/web1/cgi-bin: vi /var/www/web1/cgi-bin/speedy-test.cgi
We must make the script executable: chmod 755 /var/www/web1/cgi-bin/speedy-test.cgi (If you are using suExec, you will also have to change the owner and group of the script to match the suExec user and group of this vhost.) Now we can call that script in a browser (http://www.example.com/cgi-bin/speedy-test.cgi). You should see Hello World!, nothing else:
So Perl scripts are working, but SpeedyCGI isn't being used yet. Now let's learn about the three methods to use SpeedyCGI.
3.1 Telling Apache To Execute All Perl Scripts Through SpeedyCGIThe first method is to tell Apache that it should execute all Perl scripts through SpeedyCGI if the Perl scripts are in a certain location. We will create an alias /speedy/ that points to our cgi-bin directory, and when we use the /speedy/ address in our browser, the Perl script gets executed by SpeedyCGI, whereas when we use /cgi-bin/, the script is run without SpeedyCGI. Open the file where your Apache vhost location for www.example.com is located, and add the following lines to it (if you are using ISPConfig, you can simply paste the following lines into the Apache Directives field of the respective vhost):
Restart Apache afterwards (you don't have to do this if you're using ISPConfig): /etc/init.d/apache2 restart Now open http://www.example.com/cgi-bin/speedy-test.cgi - you should see Hello World! only which means SpeedyCGI is not being used:
Then go to http://www.example.com/speedy/speedy-test.cgi, and you should see that the script is now being executed through SpeedyCGI:
3.2 Changing The Shebang Line Of The Perl ScriptsThe second way of using SpeedyCGI is to simply change the shebang line in the Perl scripts from #!/usr/bin/perl to #!/usr/bin/speedy. That way, you don't have to reconfigure Apache: vi /var/www/web1/cgi-bin/speedy-test.cgi
Open http://www.example.com/cgi-bin/speedy-test.cgi in a browser, and you should see that SpeedyCGI is being used:
3.3 Changing The File ExtensionThe third way is to change the file extension of Perl scripts from .cgi to something like .speedy and tell Apache to run all .speedy files through SpeedyCGI. So let's create the script /var/www/web1/cgi-bin/speedy-test.speedy (an exact copy of /var/www/web1/cgi-bin/speedy-test.cgi): vi /var/www/web1/cgi-bin/speedy-test.speedy
We must make the script executable: chmod 755 /var/www/web1/cgi-bin/speedy-test.speedy (If you are using suExec, you will also have to change the owner and group of the script to match the suExec user and group of this vhost.) Open the file where your Apache vhost location for www.example.com is located, and add the following lines to it (if you are using ISPConfig, you can simply paste the following lines into the Apache Directives field of the respective vhost):
Restart Apache afterwards (you don't have to do this if you're using ISPConfig): /etc/init.d/apache2 restart Open http://www.example.com/cgi-bin/speedy-test.speedy in a browser, and you should see that SpeedyCGI is being used:
4 Links
|



Recent comments
10 hours 18 min ago
1 day 4 hours ago
1 day 6 hours ago
1 day 6 hours ago
1 day 10 hours ago
1 day 11 hours ago
2 days 2 hours ago
2 days 3 hours ago
2 days 5 hours ago
2 days 6 hours ago