Take the 2-minute tour ×

Some of the functions I am planning for a new site of mine are already available as free Perl modules. Hence I am looking at the possibility of using them, rather than coding them again in PHP. I was planning to use exec or system function to call the perl script, which will be slow. But I came across a pecl extension which allows PHP to interpret perl code.

Will this affect the performance of my other php pages, which are not using the perl script? I understand that the extra module will increase my memory usage, but other than that, will there be any issues?

share|improve this question
I'm pretty sure that calling Perl via exec/system will be much faster than running it inside PHP ... Why would that be slow? Where did you get that? –  Jan Hančič Nov 25 '10 at 11:46
Is there something that PHP needs to do on Perl output that requires PHP to call it? Is the Perl script capable of handling everything independently of PHP? –  stillstanding Nov 25 '10 at 11:48
@Jan - My question was will the extra interpreter slow down my other PHP pages. From Chas's reply, I assume it will not have an effect. –  Joyce Babu Nov 25 '10 at 12:36
@stillstanding - No. The perl modules are not independent. It just provides some handy functions like whois lookup. –  Joyce Babu Nov 25 '10 at 12:37

2 Answers 2

up vote 3 down vote accepted

It looks like all it is doing is embedding perl inside the PHP process. You should see a memory increase of a few megabytes plus any data you create in Perl. It should not slow down any code. It is just another library sitting in memory waiting for you to call it. There are two benefits of this solution: you don't have to waste time spawning another process and you don't have to parse the return values from text being printed.

Another solution is to write a Perl daemon and talk to it over a domain socket, pipe, or some other method of IPC.

You might also be interested in the Perl documentation covering embedding perl.

share|improve this answer
Can you please point me to some documentation or tutorial on how to do it with daemon? Which will be faster, interpreter or daemon? –  Joyce Babu Nov 25 '10 at 13:03
Built-in interpreter is going to be faster. The IPC is going to add some overhead, no matter what. However, depending on what Perl modules you want to access, putting them in an application daemon might be a better seperation of concerne. POE::Component::IKC was written specifically for this kind of daemon. There are also a few modules that use XMLRPC. –  Leolo Nov 26 '10 at 6:00

Are these Perl modules providing something that simply isn't available in native PHP? Or are they simple enough for you to convert them to PHP?

In other words, do you really need to run Perl code here?

Even if you don't affect performance, you will affect the maintainability of your system by adding languages.

There are times when you do need to interface between languages, but to me this doesn't sound like one of them. It sounds to me as if you'd be much better served finding or writing an equivalent bit of code in PHP.

You say in a comment elsewhere that the Perl code "just provides some handy functions like whois lookup", so I did a quick google and found this: http://www.phpwhois.org/. There were lots of other relevant looking results as well.

share|improve this answer

Your Answer


