RE: Re: PHP combined with JAVA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I would approach this problem in one of two ways

1. put all the values from the Java User object into PHP variables and store those in the session.  You might have to deal with serialization issues as mentioned below, but I think copying to PHP would get rid of this issue.

2. It almost sounds like he's trying to accomplish data persistence with the Java class.  At this point I would recommend looking into using Hibernate and PHP which would accomplish this, or look at some JavaBeans/Servlet solution which would negate the need for PHP. Most people accomplish persistence with a DB, like mentioned below the PHP/Java bridge is torn down after the page is done.

As a side note I know with the PHP-Java Bridge on sourceforge you can setup the JVM so that it won't deconstruct after each page execution.  This saves the expense of loading a JVM each time. 

To me the real advantage of PHP/Java is being able to use presentation code written in PHP with objects that are in Java.  The heavy lifting is in the Java code and the PHP just presents the data.  If more interaction than that is required I'd seriously look at the whole servlet/bean/j2ee/ejb route. 

Nate Tobik
(412)661-5700 x206
VigilantMinds

-----Original Message-----
From: Oliver Grätz [mailto:oliver.graetz@xxxxxxxx] 
Sent: Thursday, September 15, 2005 8:40 PM
To: php-general@xxxxxxxxxxxxx
Subject:  Re: PHP combined with JAVA

If I read this correctly then your question is in no way JAVA-specific.
You want to instantiate an object (which you suppose to be of large size
and slow in instantiation) and save this object in the session during
page requests.

First of all, any data put in the session array will be serialized
(read: converted into a string containing all the data in this object).
This in itself is slow for large objects. A performance gain for large
objects through using a session isn't likely.

The second problem with this - and this is the point where JAVA kicks in
- not all data in objects is serializable. The Java-API of PHP is just
some kind of adapter to the Java system. If you serialize an adapter
object then your adapter is saved but not the Java object it uses
(because PHP has no control over it). Think of the Java API as some kind
of socket connection where you only see the stuff on your side (the
client side) and the JAVA object on the "server" side is not under your
control but just used.

What happens is: you save you adapter object and the script terminates.
The JAVA VM notices that an object is no longer referenced and it is
thrown away by the garbage collection.

What could you do? Well, you could use it the other way round (Servlet
uses PHP), because then you control the JAVA side. Or you still do it
the way you do it now but write some clever JAVA code that keeps running
and retains your objects. You give those objects a name known to both
the PHP and JAVA side and this name can be serialized. You can then
re-reference any object on the next page request by its name.

AllOLLi
____________
Jayne spits a large glob of saliva on his blade,
wipes it on his shirt, shining it.
"Could you NOT do that while we're.... ever!"
[Simon on firefly 09]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux