3

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?

Joyce Babu
  • 19,602
  • 13
  • 62
  • 97
  • 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? – bcosca Nov 25 '10 at 11:48
  • *(related)* [How can I pass a url or variable from Perl to PHP?](http://stackoverflow.com/questions/4045891/how-can-i-pass-a-url-or-variable-from-perl-to-php/4046132#4046132) and [Calling Perl script from PHP and passing in variables, while also using variablized perl script name](http://stackoverflow.com/questions/3438626/calling-perl-script-from-php-and-passing-in-variables-while-also-using-variabliz/3438694#3438694) – Gordon Nov 25 '10 at 11:49
  • @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 Answers2

3

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.

Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
  • 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 06:00
1

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.

Spudley
  • 166,037
  • 39
  • 233
  • 307