Re: JAVA and PHP

From: Grant Wagner (gwagner_at_agricoreunited.com)
Date: 08/27/04


Date: Fri, 27 Aug 2004 16:56:01 GMT

Steve Sobol wrote:

> Angus Parvis wrote:
>
> > Jeremy Watts wrote:
> >
> >> how easy (or difficult) is it to pass results from a procedure written in
> >> JAVA to one written in PHP and vice versa?
> >>
> >> is this at all possible to do?
> >
> >
> > I guess the way to do this would be using JNI (Java Native Interface).

Actually, the easiest way would be to either use real Web services, or set up a simple
HTTP exchange system. In other words, your Java program would use HTTP to send
(GET/POST) requests to a server running PHP
(http://server/getCustomerNames.php?lastNameLike=a), PHP would operate on the request
and return some parsable data to the Java program (XML or some proprietary format). If
the Java program is stand-alone, this would be a client/server setup. Getting PHP to
initiate an unprovoked communication to the Java program could be difficult, if not
impossible. If the Java program itself was listening for HTTP connections on a specific
port, and informed PHP of that port, then it could be a two-way communication pretty
easily.

If you mean JSP as opposed to a stand-alone Java program, then they can also exchange
data using HTTP. This setup could easily manage two-way communication.

It would be extremely chatty, and it would be slow for large amounts of information,
but it would work. I routinely call Perl scripts from JSP
(http://server/dir_listing.pl?dir=whatever) that return directory file lists off a Web
server that the JSP does not have direct access to. Admittedly the system isn't under
very heavy load, but it works well enough.

While typing the above, I actually got thinking, it _may_ be possible to get PHP to
open a persistent socket connection, in which case you could have Java send a PHP
resource a request to open a persistent socket connection back to the Java program (ala
http://server/connectBackToMe.php?myIP=w.x.y.z&myPort=22222), and from that point
forward communicate using that. Obviously you'd probably want to do this https://, and
include a username and password. Maybe POST the request from Java so the connection
information isn't on the URL... whatever, variations on a theme.

> PHP is a scripting language, not a programming language.

I think what you meant to say is that PHP is not compiled into something that would be
available using JNI, not that it isn't a "programming language".

<url:
http://www.google.com/search?hl=en&lr=&ie=UTF-8&safe=off&oi=defmore&q=define:programming+language
/>

I see nothing there that would exclude PHP from being a "programming language". If you
wanted to define some sort of relationship between "scripting languages" and
"programming languages", you would probably have to say that "scripting languages" are
a subset of the total collection of "programming languages" (all scripting languages
are programming languages but not all programming languages are scripting languages).

(Almost) anything that has variable assignment/manipulation, loops, and logical flow
control is a programming language. This allows such things as MS-DOS batch files or
Unix shell scripts (yes, I call them "scripts", but they were written using a
"programming language" by my definition, and I don't have a problem with that, even
though the "language" is typically a bunch of native internal or external OS utilities
strung together with some logic), but excludes things like HTML (which has no looping
or logical flow control).

> PHP5 is supposed to have pretty tight integration with Java, but I don't use 5 yet.

PHP5 has no more "integration" with Java then PHP4 did. Many object-oriented concepts,
object behaviours, and exception handling have been added which make it look a lot like
Java, maybe that's what you mean.

<url: http://www.zend.com/php5/andi-book-excerpt.php />

However, you'd still have to interact with PHP5 resources on the server in the way I
outlined above.

--
Grant Wagner <gwagner@agricoreunited.com>


Relevant Pages

  • Re: Websites 101
    ... > I am presently attempting my first commercial site and was hoping I ... Google Groups, and search the archive of this group, for example ... PHP is, uhm, a very bad designed programming language which has its ... Altough learning a programming language takes a lot of time, ...
    (alt.internet.search-engines)
  • Re: How to make mod_lisp faster than php?
    ... EW> slow because someone used the wrong programming language. ... ABCL isn't very fast by ... PHP scripts start from scratch for each request ... PHP was used to process data and upload it into SQL database. ...
    (comp.lang.lisp)
  • Re: C++ Compiler On FreeBSD
    ... PHP isn't really a programming language. ... for me it's just funny thing that needs several megs of RAM to display the ... and common footer. ...
    (freebsd-questions)
  • Enhancements to PHP -- Polar
    ... I like PHP a lot. ... It's my favorite programming language. ... that would convert the script into a Linux ELF binary or EXE. ... You still need the interpreter to be ...
    (comp.lang.php)
  • Re: Pleac: Programming Language Examples Alike Cookbook
    ... :If you can programm in other scripting languages, ... PLEAC - Programming Language Examples Alike Cookbook ... :if some tcl expert has time write the missing ones. ...
    (comp.lang.tcl)