Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI/Perl vs PHP

by gilbert0 (Monk)
on Jun 02, 2003 at 17:53 UTC ( #262440=perlquestion: print w/replies, xml ) Need Help??

gilbert0 has asked for the wisdom of the Perl Monks concerning the following question:

Hi friends,

I'm pretty new to this site, pretty new to Perl and CGI to. But some thought has been bothering me for the last couple of days: is it really worth learning CGI/Perl?
I dont want to seem offensive or insult Perl or anything, but it seems that a lot of things are done in PHP these days.
Has CGI/Perl become obsolete? Or are the PHP and CGI/Perl not comparable?

Replies are listed 'Best First'.
Re: CGI/Perl vs PHP
by perrin (Chancellor) on Jun 02, 2003 at 18:15 UTC
    I don't want to seem offensive and insult you or anything, but why on earth are you asking a bunch of Perl developers if they think that Perl is obsolete? Are you going to ask some Java developers if Java is slow? And some C programmers if C is insecure?

    If you want opinions and comparisons about Perl and PHP, just Google for it. There are a billion or so web pages and newgroup postings on the subject. If you have specific questions about how Perl handles various problems, come back and ask them here.

Re: CGI/Perl vs PHP
by Beatnik (Parson) on Jun 02, 2003 at 18:03 UTC
    Actually, a lot of web based stuff is done in PHP... and I try not to sound TOO sarcastic about the a lot. Perl is loads more than just CGI... and CGI is a tad more than just perl (ofcourse 99.9% of the CGI scripts happen to be in perl). CGI/Perl and PHP are not comparable (trying to stay out of a holy war here). I'm sure PHP is good for some web based stuff but I try to prefer perl (in all it's forms, including mod_perl - which happens to be loads faster than PHP). Every PHP geek will claim PHP is better for so many reasons, every perl geek knows better.

    Greetz
    Beatnik
    ... I'm belgian but I don't play one on TV.
Re: CGI/Perl vs PHP
by hardburn (Abbot) on Jun 02, 2003 at 18:10 UTC

    In the bad old days, Perl-based CGIs were started by spawning a new interpreter for each request. As you might imagine, this was very expensive and not very scalable. You could be parsing a multi-megabyte flat-file, but start up time would still be the limiting factor for speed. These days, you can use mod_perl to embed the interpreter right into Apache (there are similar solutions for other web servers). Though there are places with a lot of legacy scripts (like where I work) that simply can't run under mod_perl.

    As far as the embedded interpeter goes, mod_perl and mod_php do the same thing for their respective language (mod_perl also gives you access to the underlieing Apache API--I'm not sure if mod_php does this). PHP as a language is basically Perl with all the fun parts taken out. Some would argue that the "fun parts" make Perl hard to learn. Even so, whenever I dabble in PHP, I always seem to knock against a problem that is easily solved in Perl, but takes a lot of hoop-jumping to do in PHP, despite the apparent similarities. Admittedly, this may have more to do with my relative experiance with Perl and PHP.

    Don't make the mistake of saying CGI == Perl. CGI is just a standard for how http servers translate data coming from an http client to a user-space program. Any time you see a server-side program take over generating a page, it's using CGI or something that looks suspiciously similar.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: CGI/Perl vs PHP
by Juerd (Abbot) on Jun 02, 2003 at 18:22 UTC

    PHP is a web-oriented language, Perl is a full blown programming language (PHP claims to be a general use programming language. It absolutely is not.) Perl does everything PHP does and more. PHP is easier to learn, Perl is easier to get things done with. Perl's often much faster. PHP was made by someone who knew, but clearly didn't fully understand Perl.

    If want something PHP-ish, but with Perl, have a look at PLP.

    Once you've got Apache with mod_perl running, installing PLP is a matter of minutes (Install the module, copy and paste a few lines to your config, restart Apache).

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: CGI/Perl vs PHP
by LAI (Hermit) on Jun 02, 2003 at 18:25 UTC

    I've done quite a bit of work with PHP. Still do a fair amount. It is great for the majority of web work out there, because it does a lot of the work for you. It is a language specifically tailored for web work, with all sorts of functions in the standard library that simplify stuff like connecting to a database, reading form input, and so on. Still, one can get into the guts of things a little bit, so you don't feel like you're being hedged into doing things a certain way.

    But that's not good enough for me.

    Like, I suspect, a lot of other Perl Hackers, I like to have an insane amount of control over my apps. I like to be able to have my web applications interact seamlessly with any other utility I've written, and to use the same libraries. PHP sucks for pretty much anything but web-application stuff, so part of the reason all my own web stuff is written in Perl is that I can have it do what I want without trying to fit the square peg of PHP into the round hole of sysadminning or whatever.

    As far as a strict comparison of CGI.pm (and other perl CGI tools) to PHP, I would have to say they are comparable. If you are comfortable with Perl, you'll prefer it to PHP. If you know a bit of Perl, but aren't fluent, you might prefer PHP. PHP was designed for the web, and it does its job pretty well.

    LAI

    __END__
      ...the reason all my own web stuff is written in Perl is that I can have it do what I want without trying to fit the square peg of PHP into the round hole of sysadminning or whatever.

      So what you are saying is perl is like silly putty, it can fit into all shapes of holes and bounces back when you drop it? :)

Re: CGI/Perl vs PHP
by mr_mischief (Monsignor) on Jun 02, 2003 at 18:42 UTC
    Perl/CGI is largely obsolete at sites that must have scalability. This is not, however, due to any form of PHP. It is due to mod_perl, which allows programs written in Perl to communicate in a much more efficient manner with a web server than CGI.

    Christopher E. Stith
    use coffee;
Re: CGI/Perl vs PHP
by cfreak (Chaplain) on Jun 02, 2003 at 21:46 UTC

    I'm stuck with PHP for most stuff in my current job. It sucks. I hate it. Sure its easy to learn if you enjoy looking up function names on PHP.net all the time. Function name for everything is a bad language design.

    Contrast to Perl which gives you a set of tools such as embedded regexes which automatically make a plethora of PHP text processing functions obsolete (Yes you can use Perl Regexes in PHP, it however is a pain, they aren't embedded and its not quite the same)

    CGI is fine for small sites without a lot of traffic. Yes PHP is faster than CGI, but if you need speed mod_perl is better anyway. Also a previous poster mentioned that mod_perl gives you access to the Apache::API. PHP does not do this, in fact doing anything with Apache using PHP is a real pain because it is intentionally separated for 'security' concerns

    Which brings me to another thing. You may hear PHP developers talk all the time about how PHP is so much more secure than Perl. Simply not true. You can write insecure programs in PHP just as easily as Perl. In fact PHP I think lures newcomers into a false sense of security because of all the "security" inherent in the system, when in reality there is nothing inherently secure in PHP.

    Yes I'm bitter about using PHP at work, I apologize :)

    Lobster Aliens Are attacking the world!
Re: CGI/Perl vs PHP
by arthas (Hermit) on Jun 03, 2003 at 09:09 UTC
Re: CGI/Perl vs PHP
by glwtta (Hermit) on Jun 03, 2003 at 17:11 UTC
    Perl/CGI is most definitely obsolete. Check out these if you want to write webapps in Perl nowadays: Personally, I've found the combination of those three to be the most flexible environment and the best disposed towards very rapid development that I've used yet. In case you are wondering, I've done development in mod_perl, Perl/CGI, JSP/Struts, PHP and ASP. Admittedly, I have not touched the last two in quite some time, and I hear they've made some great progess, but I still have a great distaste for them (anything relying on embedding logic code in HTML is just not a great solution in my book).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://262440]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2021-12-02 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (23 votes). Check out past polls.

    Notices?