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

I have two question...

What can i do to run perl faster and why php is faster than perl

I'm use php just like a module on apache and perl with sheband

but my big question is php is better than perl?

maybe, becouse php have too many function in your own core just like session, and on perl i have to create this, that is the problem?

Thank for your big help, again.
  • Comment on PHP is better than perl and what can i do to run perl faster?

Replies are listed 'Best First'.
Re: PHP is better than perl and what can i do to run perl faster?
by atcroft (Abbot) on Jun 14, 2004 at 04:41 UTC

    My first guess would be because PHP is being launched as a component of the webserver, while each time the perl script is called it is launched as an independent process. (I suspect PHP would not seem so much faster if it were being used as a CGI, rather than being loaded as a webserver module.) I would suggest if it is a significant concern perhaps a look at something such as mod_perl, where a perl interpreter would be loaded with the webserver and thus not have to be launched anew each time a call is made to that script.

    My own experience with regards to mod_perl is limited, however, so I defer to those other monks herein who may have more experience with it.

    Hope that helps...

Re: PHP is better than perl and what can i do to run perl faster?
by peschkaj (Pilgrim) on Jun 14, 2004 at 07:07 UTC

    As atcroft posited, I would also have to believe that the culprit is Perl being run as a CGI application rather than loaded as a module in the webserver. PHP isn't necessarily faster than Perl. There have been numerous comparisons on this subject, I would Google for Perl vs PHP or search on slashdot for language comparisons.

    When Perl is *NOT* run as a webserver module, every page call requires that a new Perl interpreter is spawned. This quickly becomes very expensive, both in terms of memory and CPU utilization. When Perl is run as a webserver module, one instance of the interpreter is started with the webserver and multiple threads of execution are used. The big advantage of this is that each page/script is cached in memory (in theory forever, but memory constraints might not allow for this), the memory caching allows existing scripts to be run very quickly. The scripts never need be recompiled for every page view (as they might be with a CGI application).

    Hope this helps.

    jeremiah



    If you make something idiot-proof, eventually someone will make a better idiot.
    I am that better idiot.
      "When Perl is run as a webserver module, one instance of the interpreter is started with the webserver and multiple threads of execution are used"

      Correct me if I'm wrong but with mod_perl (Apache), we have one instance of the Perl interpreter for each thread/process of the WebServer, and not the apposite.

      We also doesn't have memory cache of "pages", unless this is implemented over a embeded html system, like HTML::Mason. What we have is that for each execution of a mod_perl module we are just continuing the execution of the module, so, is like to have a script that doesn't die and only need to be parsed and started 1 time, what is much more faster.

      Graciliano M. P.
      "Creativity is the expression of the liberty".

        "When Perl is run as a webserver module, one instance of the interpreter is started with the webserver and multiple threads of execution are used"

        Correct me if I'm wrong but with mod_perl (Apache), we have one instance of the Perl interpreter for each thread/process of the WebServer, and not the apposite.

        The key word is "started". While each mod_perl process has their own copy of the perl interpreter you only suffer the time expense of starting up perl and loading modules the one time. After that it's just cheap forks.

Re: PHP is better than perl and what can i do to run perl faster?
by Aragorn (Curate) on Jun 14, 2004 at 07:04 UTC
    What can i do to run perl faster and why php is faster than perl I'm use php just like a module on apache and perl with sheband
    When PHP is used as a module, the interpreter is retained in memory, so there is no overhead for starting one up with each request to a PHP script.
    but my big question is php is better than perl?
    That depends entirely on what you're trying to do.

    Arjen

Re: PHP is better than perl and what can i do to run perl faster?
by gmpassos (Priest) on Jun 14, 2004 at 07:15 UTC
Re: PHP is better than perl and what can i do to run perl faster?
by Arunbear (Prior) on Jun 14, 2004 at 10:56 UTC
    PHP was created by teenagers for teenagers and as such is a deliberately dumbed-down version of Perl (PHP5 still lacks namespaces).

    If you want to speed up your cgi, try SpeedyCGI, FastCGI or mod_perl.

    For sessions in Perl, try this: Session
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: PHP is better than perl and what can i do to run perl faster?
by Juerd (Abbot) on Jun 15, 2004 at 18:46 UTC

    What can i do to run perl faster

    If you properly modularized your code, profiling it should be easy. If it's code that will only run in mod_perl, profiling it will be very hard. Several profiling modules are available. Search CPAN.

    why php is faster than perl

    I've found it very hard to find PHP scripts that didn't have faster Perl equivalents. But for static pages, that is: pages with no content, PHP certainly is faster than a Perl script that prints the same text, even if $r->print is used. I do not know why this is, and have no urge to find out. It shouldn't matter anyway, because for static pages, you don't need to use a programming language.

    is php is better than perl?

    Certainly not. PHP is much, much worse than Perl. Please read http://tnx.nl/php.txt for a comparison of some very important aspects.

    php have too many function in your own core just like session, and on perl i have to create this

    No, you don't have to re-invent the wheel. Others have coded things like support for sessions. All you need to do is install a module and learn to use it. It's probably a bit more work to get the session ID across, but in return you get all the flexibility you could ask for.

    hth

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