Faster way to get PHP script than LWP::Simple

J

Jason Carlton

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.
 
S

smallpond

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.
 
P

Peter J. Holzer

I assume "a little slower" means a few tenth's of a second?
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top