Slashdot Mirror


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?

19 of 174 comments (clear)

  1. A bit extreme by Bogtha · · Score: 5, Insightful

    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
    1. Re:A bit extreme by billcopc · · Score: 3, Funny

      <? bighair() { ?>
      Shot through the code,
      and you're too lame.
      You give PHP
      a bad name.
      <? } ?>

      --
      -Billco, Fnarg.com
  2. If you want to use Perl, use Perl! by Anonymous Coward · · Score: 5, Informative

    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.

  3. It's like peanut butter and chocolate... by heinousjay · · Score: 5, Funny

    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.
    1. Re:It's like peanut butter and chocolate... by Anonymous Coward · · Score: 4, Funny

      Dude #1: You got your Perl in my PHP!
      Dude #2: You got your PHP in my Perl!

      Announcer: Two great languages that only taste a little bit funny together. Now with less whitespace!!!

      Oh yeah, kids. Don't forget to try our other product, "Mac & PC". It's the cheesiest!

  4. Re:If you use PHP.... by drinkypoo · · Score: 3, Insightful

    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.'"
  5. CPAN! by schweini · · Score: 3, Informative

    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.

  6. Re:If you use PHP.... by powerlord · · Score: 3, Informative

    As Iunderstand it ... Mason, a perl based web authoring kit has been used by quite a few web sites, including Amazon.

    Yeah ... I guess their website is just painfully slow and prone to problems.

    --
    This space for rent. All reasonable inquiries will be entertained at proprietors discretion.
  7. Ruby on Rails by Anonymous Coward · · Score: 5, Funny

    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.

  8. Re:If you use PHP.... by Soong · · Score: 3, Informative

    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
  9. Just use php's functions? by Xzzy · · Score: 3, Interesting

    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.

  10. Re:Hello there, Comrade Molotov! by iwrigley · · Score: 5, Informative

    Erm... how about

    $x{'a'}{'b'}{'c'} = 'd';

    Yes, it uses references, but if you're scared of them, pretend it's a 'real' multidimensional hash.

  11. Re:If you use PHP.... by Unnamed+Chickenheart · · Score: 3, Funny

    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
  12. ImageMagick? by martinultima · · Score: 3, Informative

    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.
  13. Re:If you use PHP.... by martinultima · · Score: 4, Interesting

    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.
  14. Dear Slashdot, by edremy · · Score: 4, Funny
    I am trying to write a question that will get the maximum number of snarky replies. Taco didn't post my "Advice for converting a Ruby on Rails application to ASP.NET?" submission, so do you have another suggestion?

    Thank you
    A. T. Roll

    --
    "Seven Deadly Sins? I thought it was a to-do list!"
  15. Turck MMCache by rodent · · Score: 3, Interesting

    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!
  16. Why not use http as your connector? by joelwyland · · Score: 5, Informative

    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.

  17. Calling PHP from Perl by Dalfiatach · · Score: 3, Informative
    So you've got Perl in your PHP, is there a way to do PHP in your Perl?

    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:

    use LWP::UserAgent;
    my $ua = LWP::UserAgent->new;
    $ua->agent("PerlApplication/0.1 ");

    #construct the url (including GET params)
    my $varstring = "http://localhost/perlcalls.php";

    # Create a request
    my $req = HTTP::Request->new(POST => $varstring);
    $req->content_type('application/x-www-form-urlenco ded');
    $req->content('');

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);
    print "PHPresult: " . $res->content;
    # Check the outcome of the response
    if ($res->is_success) {

    #parse content of response
    if($res->content eq "OK"){
    print "PHP returned OK";
    }

    }
    else {
    #system failure, PHP unreachable
    print "PHP Failure!";

    }
    --
    Day by day, the penguins steal my sanity