Perl interpreter for PHP

霸气de小男生 提交于 2019-12-10 19:00:28

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4276654/perl-interpreter-for-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!