LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2009, 04:55 AM   #1
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
[webserver]cgi/perl or php


Not sure if this belongs here or in linux-server.

I'm currently doing a code audit on a web application which serves a number of pages from cgi-bin using perl scripts.

Someone asked me if it was maybe better to convert them to php and create 'normal' php pages (not using cgi-bin) or even asp.

I can not answer the question as I have never used cgi-bin or perl.

So the question is if there's much of a difference in the approach and what are the advantages/disadvantages of both methods?

I will draw my own conclusions.
 
Old 02-11-2009, 05:37 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
Hi

Lekker om nog 'n Suid Afrikaner hier te kry.

IMO it is only a matter of "taste" if you will. Using CGI will allow you to code whatever you want to do in C / C++ or another compiled / non-PHP language, and then have the application run as a normal process on your machine, triggered via CGI. If however, the task that you want to do does not require some kind of "non-php" (again, depends on your point of view) behaviour / service / activity, it might make more sense to simply use the PHP FastCGI executable to do whatever you want, thus having some cohesion across your setup.

For example, poweralert.co.za uses "deferred" PHP (executed by Apache OR via the CGI PHP executable) to build the site pages and update them every 10 minutes.

AFAIK using CGI to call a binary application is mostly useful if you have a precompiled binary that does something useful you want to tie to a webpage / site. If however, you want a high degree of consistency across your code, just do everything with PHP since PHP can run as an Apache module as well as a CGI-callable / cronnable script.

Last edited by rylan76; 02-11-2009 at 05:38 AM.
 
Old 02-11-2009, 02:48 PM   #3
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 510

Rep: Reputation: 53
It's just a matter of preference.

Perl can be used embedded into HTML "the PHP way" the same way as PHP can be installed to work as CGI only.

Perl's got the "-T" switch, which I consider a huge advantage when it comes to programming.

-T essentially enforces to check ALL incoming and outgoing "stuff" from the viewpoint of the Perl script for security issues.

Don't know wether or not PHP's got something similar.
 
Old 02-11-2009, 04:27 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It can be seen as either a blessing or a curse, depending on your situation, but PHP can be used from $HOME/public_html directories, whereas Perl used as a CGI cannot. I'm no expert on Apache or other web server configuration, so I suppose it may be possible to override these conditions, but they have always been the standard configuration on any web server I've set up.
Perl can easily be made to enforce programming rules using 'use strict;' and the '-w' switch. These can save no end of aggravation and debugging time. I don't think PHP has such a feature.

--- rod.
 
Old 02-12-2009, 05:08 AM   #5
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 510

Rep: Reputation: 53
Of course Apache can be (easily) configured to serve Perl CGIs from a user's web dir - if a webhoster offers Perl, they usally serve traditional Perl CGIs just fine.

But this is no issue of the programming language itself but of the style and configuration of the webhoster/webserver.
 
Old 02-12-2009, 06:49 AM   #6
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
PHP will scale a bit better in heavy duty than perl/cgi and in perl you can integrate more complex functionality more easily.
If you want to create an object oriented application you will be better off using mod_perl. Here all classes can be loaded by the server at server start. But it requires some more reading. So if you expect a lot of visitors this would be a good alternative.

You can use both languages in a web application simultaneously, though. You can even share sessions among the both parts with perl module PHP::Session.

Last edited by j-ray; 02-12-2009 at 09:25 AM.
 
Old 02-12-2009, 06:20 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,364

Rep: Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752
Actually mod_perl loads the perl into apache, so minimizing the startup overhead, and caching any perl scripts already run once.
mod_php does the same for PHP.

Result is a much faster site for busy sites. There are some gotchas, but the main one is that it actually caches the script state, so not just the code, but the last variable values set. So, always init all variables to a known value at first use/declaration, otherwise old values may be used.
 
Old 02-12-2009, 09:40 PM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Original Poster
Rep: Reputation: 282Reputation: 282Reputation: 282
Thanks people for the info.

The application failed the audit because of the possibility to bypass login and the fact that it does not check for POST or GET. So I can pass all my parameters in the URL and it will happily do what I tell it to do and not what the refering page wanted it to do.
 
Old 02-13-2009, 02:57 AM   #9
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
@chrism01
you can configure mod_perl to cache all scripts or not using different handlers Registry vs. PerlRun and others. If you use PerlRun the srcipts are parsed with every request as in PHP. It is still much faster than CGI but you can use usual CGI programs without completely rewriting them as it would be necessary with the Registry handler.
 
Old 02-13-2009, 11:21 AM   #10
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 510

Rep: Reputation: 53
Quote:
Originally Posted by Wim Sturkenboom View Post
Thanks people for the info.

The application failed the audit because of the possibility to bypass login and the fact that it does not check for POST or GET. So I can pass all my parameters in the URL and it will happily do what I tell it to do and not what the refering page wanted it to do.
And _that's_ just bad programming.

Just sad, that people still don't read one of the 98604860 tutorials about web programming...

And so easily avoided in Perl...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Install Apache2 webserver with PHP,CGI and Perl Support in Ubuntu Server LXer Syndicated Linux News 0 10-17-2008 06:10 PM
CMS Perl/CGI/PHP script ANU Programming 2 10-25-2006 10:11 AM
call perl cgi script from php j-ray Programming 2 01-14-2005 08:23 AM
/perl/php/cgi/mysql dramous Linux - Newbie 0 10-08-2004 05:11 PM
PHP verses CGI Perl te_conway Linux - Security 2 03-28-2002 07:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration