punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Imagine, you're given an old static html website to update. ~300 pages, classic header-navigation/body framed structure. A few Perl-based dyanmic content areas and a Perl-based search engine.

You immeditalely plan to lose the frames, and go to external css for style control and includes for global html element insertion.

Then you discover PHP. With its global "include path" setting, you won't have to worry about relative addressing in your external css links as documents get moved around the site. And with its "include" command, it's bound to be quicker than using SSI for includes. With the possibility of using variables, you can even imagine a scheme of automatically calling sub-section specific includes to vary the header content of pages.

BUT - Your Perl search engine can only output search results in html. So if you want to output search results formatted the same as the php pages, you're going to have to write a really inelegant template parser that does the work of php. The laternative is to show search rsults in a pop-up window, but that's even worse.

And THAT gets you thinking - hey, maybe this initial php/Perl issue is just the tip of the iceberg. Maybe by straying from Perl into PHP, you're setting yourself up for a whole host of nightmares down the road that will ultimately force you to choose between one or the other.

This is NOT Yet Another Perl vs PHP thread. The question is: can Perl and PHP co-exist in harmony on one website in order to exploit the best of both?




Forget that fear of gravity,
Get a little savagery in your life.

Replies are listed 'Best First'.
Re: Using Perl & PHP together
by grep (Monsignor) on Aug 29, 2006 at 21:55 UTC
    PHP and Perl can exist just fine, but you sound like you need a templating solution.

    Template::Toolkit has a [% INCLUDE section %] tag where you can setup 1 template to handle the css linking for the entire site. You can easily convert the frames to templates with a simple script. Just setup each of the frames as a template and include them during the content conversion.

    Very Simple Template Example:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>FOOBAR</title> [% INCLUDE css %] </head> <body> <table> <tr> <td colspan="2">[% INCLUDE top_nav %]</td> </tr> <tr> <td>[% INCLUDE side_nav %]</td> <td> Insert your content here </td> </tr> </table> </body> </html>


    grep
    Mynd you, mønk bites Kan be pretti nasti...
Re: Using Perl & PHP together
by Tanktalus (Canon) on Aug 30, 2006 at 04:57 UTC

    As with everyone else, I'm going to address the phase leading up to the question rather than the question. To take advantage of modern internet computing, you shouldn't be embedding your CSS in your HTML anyway. Ideally, it stays external which allows the client to download it once for your site, and not need to download it again. It can be better cached by proxies. It can be downloaded in parallel with the web page itself. Please. Don't.

    That said, I've been guilty of embedding the CSS myself - but I'm feeling much better now.

    Ok, I will answer your question now that I've gotten what I think is the important stuff out of the way. Yes, I'm sure that Perl and PHP can co-exist. Just like Perl and Java. Or shell and C. Or ... a whole host of other combinations. But you need to be careful that you don't end up needing to duplicate logic in each language. That's asking for problems - not only twice the likelihood of bugs, but that makes it infinitely more likely that you'll get the two out of sync when making changes/upgrades/bugfixes. This isn't a language thing - it's a cross-language thing. That said, just as it can be dangerous to mix, say, perl with a templating mini-language, as long as you're careful to keep each piece of logic in one and only one place, you'll probably be fine.

Re: Using Perl & PHP together
by harryf (Beadle) on Aug 30, 2006 at 12:40 UTC
    The question is: can Perl and PHP co-exist in harmony on one website in order to exploit the best of both?

    So what's the best of both?

    For PHP it's probably the execution model (when running as an Apache module) - no persistent globals, hard to knock down (other than a general Apache DOS) etc.

    Ease of programming isn't really an argument - when you do a default;

    echo "<p>".$someValueSubmittedByUser."</p>";

    ...you may be subjecting yourself to XSS - need htmlspecialchars(). Most PHP developers are themselves using template engines like Smarty which default to stuff like escaping entities.

    But think the execution model is a valid reason to have PHP being the next thing, after Apache, to handle requests.

    For Perl it's for solving the hard problems (e.g. searching, Unicode normalization etc.), everything CPAN and that it's a more powerful programming language.

    So it's a question of integration, for which you might consider one of...

    PHP::Interpreter - embedded PHP interpreter (if you control your own servers)

    Fuse, Fuse::Simple, Fuse::DBI - have been playing a little here - Fuse filesystem implemented in Perl, PHP talking via standard file system calls. Think there's potential, but not sure if you can do robust stuff this way. Also the main Perl Fuse module wants the latest greatest fuse, which doesn't seem to be packaged by many distros at the moment. Again need control over your servers.

    Call Perl as a remote daemon or shell out - slow but probably easiest (and you're only choice on a shared host). If your Perl search engine can spit out XML, PHP5's libxml2 stuff (e.g. XSLT) would be pretty effecient. There's also a couple of Perl modules able to read / produce PHP's serialized string format - php-serialization and serialize

      One further thought - if you're using plucene, there's a PHP implementation now available in the Zend framework described here. I believe they've aim for compatibility with Java Lucene so perhaps it would also work with plucene i.e. you generate the indices with plucene but use the PHP implementation to search them.
Re: Using Perl & PHP together
by duckyd (Hermit) on Aug 29, 2006 at 21:48 UTC
    I'm sure that they can, but it doesn't sound like you neccesarily have the best situation in which to use them together, if your "Perl search engine" is really as in-flexible as you say. Is there some reason you can't tweak it to output PHP?

    Alternatively, have you consdered using Mason one of the other Perl templating schemes that's available, and avoiding PHP altogether?

Re: Using Perl & PHP together
by perrin (Chancellor) on Aug 30, 2006 at 03:52 UTC
    it's bound to be quicker than using SSI for includes

    Uh, no it isn't. PHP does a ton of work, parsing every page and every include. I would expect it to be much slower than a simple SSI system.

Re: Using Perl & PHP together
by TGI (Parson) on Aug 30, 2006 at 21:02 UTC

    If most of your site is static, except for a few CGIs that are already in place, why not use perl with one of the 10,000 templating systems to generate static pages which can then be uploaded.

    This strategy will minimize your exposure to web hosting provider changes, reduce load on your server and make your pages load much faster.

    Use an automated build tool like make to automate the build and upload process and you'll have a portable, stable, easy to maintain site.

    merlyn has written an article about using TemplateToolkit in this fashion. There is also a tool called WebMake that focuses on this technique for creating and managing sites.


    TGI says moo

Re: Using Perl & PHP together
by Anonymous Monk on Aug 31, 2006 at 07:27 UTC
      it's bound to be quicker than using SSI for includes

    Apache mod_include SSI is seriously underrated.

    If you need speed mod_include is faster than mod_perl and mod_php.

    If you need more power simply integrate mod_include with mod_perl for Perl Server-Side Includes.

    From Apache Hello World Benchmarks:

    1. Hits/sec - Web Application Software
    2. 4285.2 --- C Apache API mod_hello
    3. 3557.5 --- HTML static
    4. 2475.5 --- mod_include SSI
    5. 2128.7 --- mod_perl handler
    6. 1601.2 --- mod_php PHP
Re: Using Perl & PHP together
by nmerriweather (Friar) on Sep 04, 2006 at 04:33 UTC
    what about the PHP distribution in CPAN ? PHP