Slashdot Mirror


Using J2EE and PHP together

An anonymous reader writes "There's an article in the May issue of the WebSphere Developer Technical Journal at IBM's developerWorks site on Pairing PHP with Java to meet the needs of a familiar web application scenario. The example consists of a Struts application deployed on WebSphere Application Server, which serves as the private content management tool, and a PHP 5 site to display that data to the public. Both parts of the application share a single Apache and DB2 instance."

41 comments

  1. PHP instead of JSP? by UberChuckie · · Score: 3, Interesting

    The answer to the "Why would you want to do this?" section was pretty much "because you can" and that PHP is supposed to be easier to learn vs JSP. Doesn't JSP provide the same functionality as PHP? Given the fact that you would have to know Java to do the J2EE part, I don't see how the JSP part can be a problem.

    It looked like a lot of work to get it running as well versus just dropping an EAR (or WAR) file and ask the app server to deploy it.

    1. Re:PHP instead of JSP? by Jagungal · · Score: 2, Informative

      If you know J2EE then you also should have no problems with Tapestry http://jakarta.apache.org/tapestry/ or JSF.

      PHP and JSP and the like are nothing but a parameterised buggy nightmare.

    2. Re:PHP instead of JSP? by Anonymous Coward · · Score: 0

      No, PHP has more features than JSP and much easier to use. I personally don't like PHP, but compared to JSP its a miracle!

      Sun was smoking some crack when they developed JSP!

      Seriously, most java developers suggest using an alternative template language, tapestry or webobjects (in the apple camp). Microsoft did a great job with ASP.NET, and i wish sun would fix JSP to catch up.

      Sun doesn't want you to include anything in your templates directly. Its a great idea for big projects, but for small sites its just to much work. PHP and ASP both have the advantage that they are quick to learn and non programers have a chance to use them. The real problem with PHP is the lack of API stability and subtle fixes.. like say mysql support greater than 4.0.. sure you can use mysqli but have you seen anything like message boards using the new mysqli interface? NO.

    3. Re:PHP instead of JSP? by julesh · · Score: 1

      Doesn't JSP provide the same functionality as PHP?

      No. PHP is an interpreted language with loosely typed variables, late binding and variable substitution in strings, all of which features are useful for quickly building web applications.

      JSP is just a flimsy front end onto Java Servlets, which are a much more powerful but rather harder to use environment for building larger and more complex web systems.

      The two complement each other rather well, IMO.

  2. PHP + Java + One Apache = Memory by augustz · · Score: 1

    Hahah.. I hope this is a lower volume app. I'd be curious to know a bit more about the memory footprint of this combo.

    1. Re:PHP + Java + One Apache = Memory by julesh · · Score: 1

      Memory footprint for PHP and apache is typically quite low. Java has a high overhead, but scales reasonably well. I doubt it will be a problem on any modern servers, which are likely to have 256MB or more of RAM.

  3. Why bother with PHP ? by Jagungal · · Score: 1


    Just go the whole java way - use something like tapestry:httpjakartaapacheorgtapestry Throw away the the parameter parsing and the buggy nightmare that is scripting languages imbedded in html.

    I have tried going back to the old PHP - JSP way of doing things and it is sooo painful.

    1. Re:Why bother with PHP ? by Espectr0 · · Score: 2, Interesting


      Just go the whole java way - use something like tapestry:httpjakartaapacheorgtapestry Throw away the the parameter parsing and the buggy nightmare that is scripting languages imbedded in html.


      That's way too many frameworks. I just use one of them, it's called Freemarker, check it out. Lots of features, decent speed, very easy to use and great documentation. Sure puts JSP to shame. I used it on my forum software with ldap authentication (shameless plug) and it made my life easier.

    2. Re:Why bother with PHP ? by Jagungal · · Score: 1

      That's way too many frameworks. I just use one of them

      Nope you don't - here is a quote from your link:

      FreeMarker is not a Web application framework. It is suitable for a component in a Web application framework,

      Maybe you should consider using a real framework like tapestry. http://jakarta.apache.org/tapestry/

    3. Re:Why bother with PHP ? by Espectr0 · · Score: 1

      Nope you don't - here is a quote from your link:
      FreeMarker is not a Web application framework. It is suitable for a component in a Web application framework,


      That's actually one of its best features. Think about it. It can be used ANYWHERE. Even for configuration files. It just reads objects stored on a data model and lets you do stuff with them.

      But people use it especially as a replacement for JSP. Check the a href="http://freemarker.sourceforge.net/docs/pgui_ misc_servlet.html">docs.

      Why would i use a framework that is just limited to the web, where Freemarker works as good on the web as anywhere else? J2EE isn't just for web anymore, you know...

    4. Re:Why bother with PHP ? by Anonymous Coward · · Score: 0

      You've posted that link multiple times already, please stop link-spamming.

  4. Re:Java Alternative by Anonymous Coward · · Score: 0

    Well, even though it's obvious you don't know what the hell you're talking about, since you think J2EE == applets, go ahead and check this out.

    Brain required, just FYI.

  5. Re:Java Alternative by msuzio · · Score: 2

    Slow? I hardly ever find Java slow. Is the VM slow to start up? Yes... but that really doesn't matter in most contexts where you would use it (i.e., a Web application that starts up once, then runs).

    In general, Java is very fast.

    That having been said, Perl is quite portable, and runs decently fast under something like mod_perl, where (once again) you incur the overhead of startup once, then the code runs many times.

    I wish people would stop bringing up the speed of Java, then point to applets. Very few people use applets at all these days, Flash is becoming more attractive for many of those sorts of things and is darn faster. Even Java desktop applications seem plenty zippy to me most of the time (although in some, like JBuilder, I can totally tell when garbage collection is taking place, I get freezes of the interface at times like that... something is a little wonky in how that app is written).

  6. Wha...? by Aeiri · · Score: 1

    Why do people try to create solutions for problems that don't exist?

    Some people like PHP, some people like JSP, let's just leave it at that. For the people that like both, USING both would not only be confusing but extremely resource intensive.

    1. Re:Wha...? by FriedTurkey · · Score: 3, Interesting

      If you RTFA it isn't talking about JSP. It is about using Java in the middleware (WebSphere) and PHP in the presentation layer (Apache).

      There is actually a lot of use for this as a web developer is often someone on a seperate team as the application business layer team.

      Why should a PHP web site be rewritten in Java/JSP to use a existing Java middleware module?

    2. Re:Wha...? by dereference · · Score: 3, Informative
      If you RTFA it isn't talking about JSP. It is about using Java in the middleware (WebSphere) and PHP in the presentation layer (Apache).

      With all due respect, this is quite incorrect. If you re-RTFA carefully, you'll see:

      The example consists of a Struts application deployed on WebSphere Application Server V5.1, which serves as the private content management tool for entering information by the Catabase team. A PHP 5 public site will display the content and enable users to search for animals based on their attributes. The database shared by both components is DB2 UDB Enterprise Server Edition Version 8.2. The Web server instance for both portions is Apache 1.3.

      So yes, basically they have a Struts part (hosted by WebSphere acting only as a J2EE Web Container) for the "internal" web site, and a PHP part for the "external" web site. The only things shared are the HTTP server (which invokes the PHP or Struts modules) and the database (which is read by PHP and read/written by Struts).

      There is no "middleware" to speak of here.

    3. Re:Wha...? by FriedTurkey · · Score: 1

      They may be running on the same server but it is still middleware processing business logic. It doesn't have to be on another physical box to be middleware.

    4. Re:Wha...? by dereference · · Score: 1
      They may be running on the same server but it is still middleware processing business logic.

      Right...but that wasn't my point at all. I wasn't disputing that "middleware" is involved (although I must say I disagree with the broadness of the second definition of the term in Wikipedia). I was instead suggesting that it was misleading to imply that the example included Java middleware under a PHP presentation layer. They've got a Java presentation tier with a Java business tier and a database back end. They've also got a PHP presentation tier with a (trivial) PHP business tier and the same database back end.

      So, the Java business tier (what you are calling middleware) is only bridging between the Java presentation tier and the database; it has nothing to do with the PHP components. The PHP business tier is interacting only with the PHP presentation tier and the database; it does not interact in any way with Java. If anything, it is the database itself (and--to a much lesser extent--the HTTP server) that bridges PHP and Java in this example.

    5. Re:Wha...? by FriedTurkey · · Score: 1

      OK I got what your saying now compadre. The PHP doesn't talk to the Java middleware.

    6. Re:Wha...? by ahdeoz · · Score: 1

      Yeah, that article was a total waste of time.

      The first half was completely superfluos stuff...

      "The 'web' is a shortened version of the acronym I.N.T.E.R.W.E.B which was invented by Marc Andresson at Darpa in 1989, in collaboration with Vint Cerf (who claims he just cribbed Al Gore's notes from "Love Canal", a nuclear particle physics thriller documentary)

      And the second half is simply:

      type ./configure && make && make install to install Apache with PHP. And don't forget to make sure you have KDE with Redhat's bluecurve theme installed in the server.

      Then it ends quickly by saying "Now install the application, and voila!"

      I guess the whole point was to explain that a database can have more than one cleint connection, but if you copy the recipe for a webserver and rename it, it's a different webserver.

  7. Re:Java Alternative by FriedTurkey · · Score: 1

    As a long time user of JBuilder, the old versions were terribly slow. No problems with version 9. I guess it also helps that I am on a faster computer than when I used earlier versions.

    I still think the JBuilder Personal Edition is the best "free" Java development platform out there. It doesn't do servlet programming OTB but I found I could just add the servlet classes and then move the classes.

    BTW: The parent is a troll.

  8. Sure.. by Joff_NZ · · Score: 2, Interesting

    We've been using this mix ourselves for a little while now... the main core of the application is deployed on JBoss, where all the heavy processing occurs, with scheduled jobs etc running via Quartz

    The web-based components that the users interact with are written in PHP5 - a decision that was not made based on any sort of execution speed differences that may or may not exist between PHP and JSP, but on the shorter development time we were going to have with PHP

    Whole thing works very well :-)

    --
    The revolution will not be televised. It won't be on a friggin blog either
  9. god, no! by namekuseijin · · Score: 0, Troll

    isn't Java bad enough already?!

    just imagine all the verborragic redundancy of Java/Struts + loads of xml with PHP's "1 millions inconsistently named functions in the same namespace" + global variables abound...

    plus, both interpretetive performance hogs...

    --
    I don't feel like it...
    1. Re:god, no! by pebs · · Score: 1

      isn't Java bad enough already?!

      I would say isn't it good enough already?

      plus, both interpretetive performance hogs...

      Java isn't interpreted. In any case, what do you propose be used for web applications?

      --
      #!/
    2. Re:god, no! by namekuseijin · · Score: 2, Insightful

      "Java isn't interpreted."

      sorry, call it just-in-time compilation if you like, but no matter how you look at it, it's still a language (bytecodes) being translated to another language ( native ASM ) in execution-time ( execution of the JVM, that is ). That's interpretation for me, not compilation.

      "In any case, what do you propose be used for web applications?"

      How about Ocaml, Python, Scheme, Haskell or Ruby? Powerful, modular, flexible and concise languages for a powerful, modular and flexible environment like the web...

      or perhaps just wait for Links...

      --
      I don't feel like it...
    3. Re:god, no! by julesh · · Score: 1

      sorry, call it just-in-time compilation if you like, but no matter how you look at it, it's still a language (bytecodes) being translated to another language ( native ASM ) in execution-time ( execution of the JVM, that is ). That's interpretation for me, not compilation.

      Strange, sure sounds like compilation to me. Just compilation that's delayed until it's needed. Interpretation implies that it is done on every execution, not just the first.

      Ocaml, Python, Scheme, Haskell or Ruby?

      All of which are either interpreted or just-in-time compiled, if I'm not mistaken.

      Not that I disagree with your choices, some of these are great languages, but don't complain about an aspect of another language that your own preferences have in common with it.

    4. Re:god, no! by namekuseijin · · Score: 1

      compilation that's delayed until it's needed. Interpretation implies that it is done on every execution, not just the first.

      Interpretation that way is no more ever since old basic days. These days, almost all "interpreted" languages either compile the concrete syntax to some form of bytecode and then execute it, or simply compile it once to bytecode and load that fast, instead. Ruby and Python work that way.

      Anyway, yes java compiles to native "just-in-time" just once -- at start-up time. At that time, it's being interpreted. It's also interpreting anytime some new module is loaded, at execution time, when it too will be translated from bytecode to native ASM. Also, it's a performance hog for the loads of stupid libraries that suffer the same process and are needed by even rather simple programs.

      All of which are either interpreted or just-in-time compiled, if I'm not mistaken.

      Haskell and Ocaml compilers generate fast native ASM, ahead-of-time.

      --
      I don't feel like it...
  10. Re:Java Alternative by Anonymous Coward · · Score: 0

    C#/.NET

  11. I'm doing this already by smartfart · · Score: 2, Interesting
    Well, almost. My client is purchasing a medical database application that runs on Tomcat and MySQL (save the flames, please), and I already have two projects planned that will add functionality that the vendor doesn't provide.
    1. A sign-in kiosk in the patient waiting room for new patients to input their personal information (name, address, insurance provider,reason for visit, etc.).
    2. An externally-accessible portal for the clinic's customers (they do a lot of occupational medicine) to view information regarding their employees that have been sent to the clinic for drug screens, injuries, etc.. The database vendor provides a hosted web portal for $100 per month, but it's limited in that each patient is required to have his own login, and only one patient is viewable at a time. This limits the employer's ability to view all the employee records, obviously.

    My client was already sold on the system (they reviewed three competing products), and my promises of ease-of-extensiblilty utilizing PHP was icing on the cake :-)

  12. Any secure way for Apache + Tomcat ? by Anonymous Coward · · Score: 0

    If I use Apache at port 80 and say Tomcat at port 8080 then I can use the Apache proxy to handle both Java and PHP requests. Unfortunately the Apache proxy can be abused by spammers (relaying). Is there any solution for this problem?

    1. Re:Any secure way for Apache + Tomcat ? by Anonymous Coward · · Score: 0

      run tomkat as an apache module?

    2. Re:Any secure way for Apache + Tomcat ? by julesh · · Score: 1

      Don't turn ProxyRequests On; use RewriteRules to specify what proxying to perform. This should be secure.

  13. LOL by militiaMan · · Score: 0

    This is just stupid. I will use PHP on servers without Java, but that is it. I like both languages, but PHP is rather limited for large projects. PHP has no Interfaces and it is not really object oriented.

  14. Re:Java Alternative by Anonymous Coward · · Score: 0

    I still think the JBuilder Personal Edition is the best "free" Java development platform out there.

    Have you tried Eclipse 3.0? I've worked with recent versions of JBuilder (as well as older ones), and I can say that Eclipse is MUCH better than JBuilder. JBuilder is completely horrible in comparison (at least with whatever version was out last summer, it was terrible, didn't even have proper refactoring features). Borland has even announced that they are porting to an Eclipse-based product.

    JDeveloper, Oracle's IDE which was original based on an older version of JBuilder, is equally bad and I recommend staying away from that as well, especially the pretty lousy ADF framework that they push along with it.

    I've heard good things about Netbeans 4.1, but haven't tried it out yet.

  15. Re:Java Alternative by Anonymous Coward · · Score: 0

    My problem is the amount of memory it takes to run tomcat on a webserver. I have a freebsd box with 512mb ram and half of it is just java & tomcat!

  16. Re:Java Alternative by Anonymous Coward · · Score: 0

    Even better. Perl with CGI::Fast. 4 times faster than some PHP scripts i've replaced.

  17. Re:I'm doing this already by LadyLucky · · Score: 1
    Hmmm, Medical Applications Portal...

    Take a look at Concerto. Yes, I work for this company.

    --
    dominionrd.blogspot.com - Restaurants on
  18. Re:Java Alternative by LoztInSpace · · Score: 1

    You'd be wise to stay with 9. I "upgraded" to X then 2005 and my system has never been the same since. It's slow, buggy, web projects are restructured, libraries go awol. Total mess. Maybe I just didn't rtfm, but it's been a nightmare.

  19. When Java? When PHP? by Anonymous Coward · · Score: 0

    An interesting discussion exists at Java vs PHP
    Some strong arguments in favor and against using Java, PHP and both of them together.