PHP and Perl in One Script?
gbulmash asks: "Recently, I began working on a graphics project and wanted to use ImageMagick. As a PHP coder, I figured I'd use MagickWand for PHP. But after some investigation, I decided that an alpha at 0.1.8 with sparse documentation just wasn't going to be good enough for production use. I decided that PerlMagick would be a much better API, but I didn't want to code the whole project in Perl. In the end, I found a cool package for embedding Perl code in PHP scripts (with an article on its use) and it went to a 1.0.0 release, earlier this year. I think I've found my answer, but before I make a final decision and go ahead with it, I thought I'd ask the knowledgeable Slashdot crowd: Is there a better way of interfacing Perl with PHP so you can get the best of both worlds?"
So you've got Perl in your PHP, is there a way to do PHP in your Perl?
Why didn't you use the ImageMagick extension in PECL? There's plenty of image processing options with PHP, just because MagickWand didn't work out for you, that doesn't mean you have to concoct a monstrous hybrid of PHPerl.
Bogtha Bogtha Bogtha
Instead of going with some bizarre rube-goldberg hack like this (does it even work with dynamically loadable Perl modules?), just write a separate Perl script that does what you need and receives data on standard input and gives responses on standard output. Use PHP's proc_open() function. You can even set up the Perl script as a daemon, if you like, and get higher performance.
I used this same trick to interface a binary-only executable to my PHP script. You can even use XML to pass the data back and forth, if you swing that way. I don't know how this might work on Windows, if that's what you're running on.
By the way, version numbers mean absolutely nothing except the author's opinion of his own software. In fact, the article you posted says: "the extension is still marked EXPERIMENTAL". Sounds like alpha to me.
Not to mention, this is the same guy that wrote Turck MMCache and in my testing, mmcache couldn't stay stable for more than a day or two, and would randomly return junk characters instead of output from our PHP scripts. Not exactly an author I'd trust for this kind of lower-level stuff. (Yeah, I know, there are 10 billion geeks who used MMCache on their 5-hit-per-day blog and it worked perfectly, and will not hesitate to point this out. It just didn't work for me, and other products did, sorry!)
For what it's worth, I've used "pecl-imagick-0.9.11" on my Gentoo servers to manipulate images (basically, to generate thumbnails by resizing and sharpening) and it works perfectly. I think this is different than what you're talking about. So unless you really just can't live without Perl (?), try that first.
Instead of looking at version numbers, test thoroughly.
I can't see any possibility of flamewars in this subject.
There is, alas, a reason. Much wider scope for takeup of your script. Plenty of ISPs offer a well configured PHP interpreter, but most do not offer a very wide or up to date CPAN selection.
All the security of PHP and all the readability of Perl? It's a surefire win. I wonder why the whole world hasn't caught on to this one yet?
Slashdot - where whining about luck is the new way to make the world you want.
Do most hosting providers provide the software necessary to embed perl in php? If not, this is a non-conversation. Mine doesn't even give me a compiler, I have to beg if I want anything (or compile a static binary somewhere else.) To be fair, they were plenty responsive the one time I asked for anything.
"You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
Ahhh, nothing like a good flamewar! OK, I'll bite. Tell me, please, how do you write multidimensional arrays in Perl? No, no, you are *not* allowed to use references! Or what about a multidimensional hash? Suppose I wanted to migrate from PHP to Perl, how would I translate this perfectly valid PHP code to Perl:
$x["a"]["b"]["c"] = "d";
I mean, can you do it the Perl way, with less keystrokes?
as almost always, CPAN is your friend in all things perl-related.
aside from that, i really don't understand why you'd use PHP if you're familiar enough with perl to use it.
As Iunderstand it ... Mason, a perl based web authoring kit has been used by quite a few web sites, including Amazon.
... I guess their website is just painfully slow and prone to problems.
Yeah
This space for rent. All reasonable inquiries will be entertained at proprietors discretion.
I'm probably going to get flamed for this but have you considered using rails? Seriously, you just spend a couple of hours installing it on your development box before you discover the speed and power of rails. Then when you've used the programming equivilent of a lumphammer to sculpt your fine detailed script, you get to spend the next week looking for hosting. I do all my development on a gentoo box, it only took me a weekend to set up from stage 1. I have some great USE flags that make my RAILS development go super fast and gentoo only takes about 1.5 hours a week to maintain. Well, sometimes it takes a little longer because the QA is non-existent of late.
That's what I'd do anyway, RoR running on gentoo with some kicking USE flags. I'm developing a complete Ajax OS in my spare time using this system. It's going to revolutionize the OS market and yes, it will have use flags.
Huh, some perl driven web apps:
http://www.slashcode.com/
http://scoop.kuro5hin.org/
I have been trolled. Hope this helps. Have a nice day.
Personally I prefer Java Servlets, with perl a second place, then python, then bash, then C, then php.
Start Running Better Polls
I know ImageMagik is the kitchen sink of image editing, but have you looked into PHP's embedded image functions? There's very few effects you couldn't produce on your own with those functions. I'll grant it's probably easier to just pass arguments to the ImageMagik library, but probably not more efficient.
Allows you to avoid the problems of calling ImageMagik, piping it through perl, then doing whatever you need to do in PHP. Sounds like a recipie for excessive server load, to me.
I am in no way an expert of programming nor web... ...but from my surfing experience, it seems like html + PHP creates very fast websides.
(And PHP can do funky things like change colours on events like mouseover etc? groovy! )
urd
I tend to use ImageMagick a lot via PHP scripts, but not with any sort of polyglot of code or anything – I just use exec("convert ... ");. It's probably not the most cross-platform way, but since I tend to do exclusively Linux/UNIX-based stuff, and most of the code is only used by me for my own sites anyway, it's not a problem at least as far as I'm concerned.
Creative misinterpretation is your friend.
Bit off-topic, but if you need those kinds of features (compilers, custom Perl modules, etc.) maybe check out one of the user-mode Linux Web hosts like Linode.com – they've been running my site for a few months, and I'd say it's probably the best thing since Al Gore invented the Interwebs :-) You get your own distribution, your own choice of server configurations... it's like a dedicated server without the dedicated server. [Not trying to sound like an advertisement or anything like that, just a very happy user recommending a useful service.]
Creative misinterpretation is your friend.
Come now, you sound like every other expert PHP programmer to me.
Whoa, not for lexicals.
Nope, only after you've already dereferenced one level.
how to invest, a novice's guide
Thank you
A. T. Roll
"Seven Deadly Sins? I thought it was a to-do list!"
There's like ten bazillion ways to integrate PHP with Image processing tools like Image Magick just like with any other OSS language. Only more so because the PHP userbase is largest. No need to use some Hack involving Perl. Typo3 (www.typo3.org) uses Image Processing to generate Menubuttons and stuff, there are countless other PHP projects out there doing the same, and it's no sweat at all to start the imagemagick CLI tools (contvert, etc.) including parameters from PHP. 30 lines of code max I'd say. Do you homework and then ask in some PHP forums and mailinglists for sample code. You'll get answers in no time.
We suffer more in our imagination than in reality. - Seneca
I have to say I used Turck MMCache on an 80 server farm serving up >4 million page loads (not hits) per day with not a single problem. This was back in the PHP4 days. Based on the load on the machines it could have easily been done with 5 but management wanted to spread the risk in an insanely large manner.
rodent...
Tactical nuclear weapons are a viable alternative!
Congratulations! You found the worst of both worlds.
Why do you need them to work in the same script? Have your PHP generate an img tag that references the perl script in the src attribute. Then the web browser will fetch the image data directly from the perl script and you don't need a Frankensteinian monster.
"Pearl and PHP DNA... just don't mix"
Just wondering. :-)
http://blog.sykosopp.com/2006/02/26/one-file-to-ru le-them-all/
// comments, trigraphs disabled).
Embed all your languages, this file can be interpreted or compiled in 7 different coding languages:
$ php poly.sh.pl.php.tcl.cpp.bf.py.c.lhs.txt
#I'm a PHP script
$ python poly.sh.pl.php.tcl.cpp.bf.py.c.lhs.txt
I'm a Python program.
$ perl poly.sh.pl.php.tcl.cpp.bf.py.c.lhs.txt
I'm a Perl program.
$ tclsh poly.sh.pl.php.tcl.cpp.bf.py.c.lhs.txt
I'm a tcl script.
$ sh poly.sh.pl.php.tcl.cpp.bf.py.c.lhs.txt
I'm a sh script.
Rename file to compile in C/C++:
$ gcc p.c -o c;./c
I'm a C program (C89 with
$ g++ p.c -o cp;./cp
I'm a C++ program, trigraphs disabled.
Hallvar Helleseth (hallvar)
Using too many languages is bad?
Hell, then a page of mine that uses all of:
* bash
* C
* C++
* Perl
* perhaps even Python or some such (hell, I don't look under the pants of programs I call)
* sed
* grep
And as far as I know, this is not a rare practice. If it's not a CPU-critical script, bash makes for good glue code. And you can't call it hard to maintain (at least until you look at sourceless configure scripts).
The creatures outside looked from Alt-Right to Antifa; but already it was impossible to say which was which.
For instance, accessing variables that are not defined returns nothing by default (most languages will throw an exception should this happen). This results in problems like this occuring.
There are plenty of easy to learn languages such as Python and Ruby out there that do not have nearly as many problems, so there is not too much of an excuse to use PHP for anything but the simplest web page. What this guy is trying to do, use PHP despite the fact that it is obviously not powerful enough for his requirements), is just wrong.
Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.
I am in the joyous position of having to maintain a monstrosity of an application that was written by at least 4 different programmers over a period of years with numerous kludges plastered on top of a highly dodgy initial design.
A lot of the early code was in Perl. Obfuscated, unreadable, indecipherable (and uncommented) Perl. So I decided to re-implement whole libraries of functions in PHP instead. But...a lot of what goes on in the application is driven by 2 Perl daemons, and they needed access to the new PHP libraries too.
So:
Day by day, the penguins steal my sanity
There is a php application that I've written and am still writing, and I really wish I had gone the Perl route in stead. In PHP when you hit the wall, you hit it fast and hard. The most infurating thing is when they changed default settings which broke a lot of helper libs, which were abadoned by the developers. I'm with you and now I'm converting my app to Perl and CPAN modules; no sense in developing my app, and debugging other peoples libs.
Apocalypse Cancelled, Sorry, No Ticket Refunds