Faster way to get PHP script than LWP::Simple

Discussion in 'Perl Misc' started by Jason Carlton, Nov 29, 2009.

  1. I'm using a PHP script as a heading for the site, and it has several
    functions in it. If I want to include this header in a Perl script, is
    there a better / faster way than using LWP::Simple?

    I ask because I've noticed that my Perl-based pages load a little
    slower than other pages on the site (even a plain "Hello World" script
    that includes this header), so I'm pretty sure that this is the
    bottleneck.
    Jason Carlton, Nov 29, 2009
    #1
    1. Advertising

  2. Jason Carlton

    smallpond Guest

    On Nov 28, 9:50 pm, Jason Carlton <> wrote:
    > I'm using a PHP script as a heading for the site, and it has several
    > functions in it. If I want to include this header in a Perl script, is
    > there a better / faster way than using LWP::Simple?
    >
    > I ask because I've noticed that my Perl-based pages load a little
    > slower than other pages on the site (even a plain "Hello World" script
    > that includes this header), so I'm pretty sure that this is the
    > bottleneck.


    time perl -e 'use LWP::Simple; print "Hello, World"'
    Hello, World
    real 0m0.033s
    user 0m0.026s
    sys 0m0.007s

    You must be very perceptive. Most people
    wouldn't notice that delay.
    smallpond, Nov 29, 2009
    #2
    1. Advertising

  3. On 2009-11-29 18:28, smallpond <> wrote:
    > On Nov 28, 9:50 pm, Jason Carlton <> wrote:
    >> I'm using a PHP script as a heading for the site, and it has several
    >> functions in it. If I want to include this header in a Perl script, is
    >> there a better / faster way than using LWP::Simple?
    >>
    >> I ask because I've noticed that my Perl-based pages load a little
    >> slower


    I assume "a little slower" means a few tenth's of a second?

    >> than other pages on the site (even a plain "Hello World" script that
    >> includes this header), so I'm pretty sure that this is the
    >> bottleneck.

    >
    > time perl -e 'use LWP::Simple; print "Hello, World"'
    > Hello, World
    > real 0m0.033s
    > user 0m0.026s
    > sys 0m0.007s
    >
    > You must be very perceptive. Most people
    > wouldn't notice that delay.


    I'm quite sure that he doesn't just load LWP::Simple without using it.

    From the description he uses LWP::Simple to get a PHP-generated page,
    then extracts the header from it and includes it in the output of his
    Perl script.

    So the total time is:

    1) startup of the perl script (if this is CGI, this includes loading the
    perl interpreter and all modules used by the script)
    2) plus the time for fetching the PHP page
    3) plus the time for extracting the header (almost certainly negligible)
    4) plus the time the script spends on doing "real work".

    So loading a perl page always takes as long as loading a PHP page
    (because loading a perl page *does* load a PHP page, too!) plus some
    extra time.

    Obvious optimizations are:

    * If you have to load a PHP page every time you load a perl page, then
    at least load one which is short and loads fast! Don't load your
    start page which searches for your last n blog entries, does a google
    search for your name and aggregates 52 atom feeds just to throw all
    that information away immediately.
    * Cache the result of the query. If you use FastCGI or mod_perl, you
    can simply keep the header in a variable. If you don't you can put it
    in a file or stuff it into memcached.
    * Use FastCGI or mod_perl. The time to load the perl interpreter may be
    negligible these days, but some other actions aren't. For example
    opening a database connection is still rather slow, and if you can do
    that only once instead of for each request you win.

    hp
    Peter J. Holzer, Nov 29, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve
    Replies:
    17
    Views:
    681
    Mike Smith
    Sep 13, 2004
  2. Replies:
    24
    Views:
    10,492
    arizonace
    Mar 12, 2013
  3. Rajive Narain
    Replies:
    0
    Views:
    1,545
    Rajive Narain
    Sep 18, 2009
  4. Hon Guin Lee - Web Producer - SMI Marketing

    LWP::Simple get() problem

    Hon Guin Lee - Web Producer - SMI Marketing, Sep 26, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    81
    Michael Budash
    Sep 26, 2003
  5. __
    Replies:
    1
    Views:
    107
    Gregor Kofler
    Oct 2, 2007
Loading...

Share This Page