Page 1 of 1

Mixing PHP and Perl... or PHP and PHP-cli

Posted: Tue Aug 20, 2002 8:17 am
by nielsene
So my current project has grown to the point where it needs a whole mess of backend scripts to help keep the frontend quick and responsive.

Currently I'm taking the extremely insecure method of letting my PHP (mod_php style install) write some static html files, some pregenerated PHP lookup tables, and LaTeX->PDF files into the web tree and invoking the scripts through wget. I want to change this to a more secure model and that requires using some proper backend script that doesn't go through the web server so I can setup good permissions, etc.

I'ld like to use Perl for these backend scripts because its less demanding than requiring two differently configured installs of PHP. I'ld also like to be able to use my library of PHP code. While porting the scripts wouldn't be too hard, I don't want to maintain two sets of class files. Has anyone seen a good way of mixing PHP and Perl code? Or should I just install two PHPs?

Posted: Tue Aug 20, 2002 8:26 am
by llimllib
I remember a posting on phpdeveloper.org [here] about putting two PHPs on one machine.

<language bigot>And please, save people's eyes. Use python, not perl, if you choose not to use PHP.</language bigot>

Posted: Tue Aug 20, 2002 8:42 am
by nielsene
Seeing how I don't know either Perl or Python, but have stacks of O'Reilly books on both maybe I'll go with Python.

I've been trying to learn Perl first, just because I feel like I'm missing something if I don't know it, no matter how many other languange I use. But I just can't get into it. Yes people can write bad code in all languanges, PHP or Perl or Java or whatever, but I'm not used to reference/teaching books promoting the practice in the name of "culture." I know that I don't have to follow culture and can do it the way that is "right" for me, but it makes me cringe.

Still with Python the original question remains, is there a way to use PHP classes from within Python? I guess even if I can't, at least Python gives me a more feature complete OO playground and I might not mind reimplementing as much..... and I could factor out some bits that only the backend scripts need, might make a cleaner class model even with some of the classes existing in both.

As to doing the two installs of PHP, its not that I have trouble doing it, the sourceforge offsite I run has both cgi and module versions running, its more that it feel a little inelegant to me and complicates the installation procedure greatly. Perl and Python, to a slightly lesser degree, are almost universal and't impose additional pre-installation requirements. I hope to have other developers join me in my project, but if its too hard to set up a working development environment.......

Posted: Tue Aug 20, 2002 8:54 am
by llimllib
<drools over stack of O'reilly books>

ahem..anyway, I totally agree with you on Perl. I like the fact that perl references (the few I've read) tend to be humourous, but the language itself is just ugly. I had to learn a little bit for a project I was doing, and I will never do that again if I can avoid it.

Now, back on topic, I would base my choice of language on the size of the project vs. the applicability of my libraries. If you already have PHP libraries that do most of what you want, plus you feel much more comfortable in PHP, I would just take the inelegance and be as clean with my code as possible,
If, however, you will be developing a bunch of new libraries, I honestly feel that Python is a better system scripting language with MUCH better Object Orientation. This will make your libraries more portable, more maintainable, and just plain sexier. The language itself (esp. with all those o'reilly books available :)) is ridiculously easy to learn, and just well designed.
To learn the language, I decided to write a library for changing ID3 tags (even though it already existed). Honest to god, it took me TWO DAYS from a standstill, absolute 0 knowledge of Python. Since then, I've been an advocate.

So, to sum up, your choice is between sexiness and ease, and only you can make that judgement call for yourself.

Posted: Tue Aug 20, 2002 8:57 am
by llimllib
whoops, forgot about mixing. You could check out Python in PHP (PIP) to put python code into PHP. Never tried it, but it sounds really cool.

Posted: Tue Aug 20, 2002 9:06 am
by nielsene
Ooh thank you! Python In PHP looks very interesting... The performance hit may be too much, but its definately worth trying. Time to stop reading Perl and start on Python.

Posted: Tue Aug 20, 2002 9:10 am
by llimllib
If you do try it, let me know what you think of it. I've meant to, and just haven't gotten around to it.

Posted: Tue Aug 20, 2002 9:31 am
by nielsene
I'll probably test it out later this week. I'll report back on the findings... My only Python reference at present is the Programming Python I've been planning to pick up Learning Python (both O'Reilly), unless there is a better one you (or other posters) would suggest.

Posted: Fri Sep 20, 2002 8:53 am
by nielsene
I've played a little with PIP now. Its not as quick as I'ld like, but still rather fast. As I'm on a Debian system it was trivial to install the php4-cgi package to do command-line php and not have to port my classes to Python for use in both languages via PIP.

While I know doing so has probably limited the number of people who will end up running servers with my software, it seems like the right approach technically.