[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Akos Maroy
Ivan Ristic wrote:

  No, I have been told (by someone, I do not remember) that if you
  use PHP as a servlet ext/java would use the same JVM. I haven't
  check to see whether that is correct.


My experiences:

using php-4.2.3, calling plain php pages from Tomcat seem to be OK. But 
when calling java code from within the PHP code, I get a native mode 
exception:


Unexpected Signal : 11 occurred at PC=0x4DAD935E
Function=zend_hash_index_update_or_next_insert+0x3A
Library=/.../php-4.2.3/libs/libphp4.so

Current Java thread:
at net.php.reflect.setResultFromObject(Native Method)
at net.php.reflect.setResult(reflect.java:105)
at net.php.servlet.readCookies(servlet.java:92)
at net.php.servlet.send(Native Method)
at net.php.servlet.service(servlet.java:188)
at net.php.servlet.service(servlet.java:212)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)



I also tried the CVS version, but I can't even compile it:


/.../php4/sapi/servlet/servlet.c: In function Java_net_php_servlet_startup':
/.../php4/sapi/servlet/servlet.c:261: warning: passing arg 2 of 
`php_module_startup' from incompatible pointer type
make: *** No rule to make target `sapi/servlet/java.c', needed by 
`sapi/servlet/java.lo'.  Stop.


What java.c is expected here? The same as in ext/java ?


Akos


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



[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Akos Maroy
Ivan Ristic wrote:

  No, I have been told (by someone, I do not remember) that if you
  use PHP as a servlet ext/java would use the same JVM. I haven't
  check to see whether that is correct.


sound good, I'll take a look.


Akos


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Ivan Ristic


  There is a servlet which accepts requests and uses native
  code from libphp4.so to execute them. At the same time,
  the Java extension is used to provide access to Java
  objects from PHP itself.



but the ext/java as it is would not be suitable, as it would spawn new 
JVMs every once in a while (thus it would use a different JVM then the 
one that called the PHP page).

  No, I have been told (by someone, I do not remember) that if you
  use PHP as a servlet ext/java would use the same JVM. I haven't
  check to see whether that is correct.



Where can I find documentation for calling libphp4.so? How do I execute 
a PHP script by calling some functions in libphp4.so?

  /sapi/servlet


Bye,
Ivan


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Maróy Ákos
Ivan Ristic wrote:

  There is a servlet which accepts requests and uses native
  code from libphp4.so to execute them. At the same time,
  the Java extension is used to provide access to Java
  objects from PHP itself.


but the ext/java as it is would not be suitable, as it would spawn new 
JVMs every once in a while (thus it would use a different JVM then the 
one that called the PHP page). the solution would be to pass the JVM 
somehow to the PHP page (maybe as a global variable?), and then make it 
use that JVM when executing JNI calls.

So a solution would be then:

- from java, use JNI to call function in libphp4.so
- libphp4.so, properly called, would execute a PHP script
- this PHP script could call java functions through JNI, using a JVM 
passed to it somehow

Where can I find documentation for calling libphp4.so? How do I execute 
a PHP script by calling some functions in libphp4.so?


Akos


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



[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Ivan Ristic


  You can perhaps try to use it the other way around, have PHP
  run inside a Java VM. You can also try to get the source code


how would this work? can you send me pointers?


  There is a servlet which accepts requests and uses native
  code from libphp4.so to execute them. At the same time,
  the Java extension is used to provide access to Java
  objects from PHP itself.

  Everything you need is in the PHP source, go to
  folders /sapi/servlet and /ext/java for instructions.

  Actually, get the fresh source from CVS, it will work better.

  Last time I tried this it worked, but barely (on Linux with
  JDK 1.4). I plan to try it again today since new patches have
  been added in the meantime.

Bye,
Ivan



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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Akos Maroy
Ivan Ristic wrote:

  You can perhaps try to use it the other way around, have PHP
  run inside a Java VM. You can also try to get the source code


how would this work? can you send me pointers?


Akos


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




Re: [PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Derick Rethans
On Thu, 5 Dec 2002, Maróy Ákos wrote:

> Derick Rethans wrote:
> > Have a look at www.vl-srm.net, and more even the article about it @ 
> > http://www.vl-srm.net/doc/articles/php-almanac-2002.php (the part about 
> > Bananas might be th emost relevant thing).
> 
> Thanks for the info. Though I could implement a similar deamon in java, 
> and call it through XML PRC or other similar way via a network socket. 
> (As my original intention was to fire up a JVM and call java functions 
> from there.) But using network sockets is far mor expensive than calling 
> through JNI. In my case, it seems that such a solution would not worth it.

You can use UNIX domain sockets, which boosts performance a _lot_. And 
SRM has no XML bloat as overhead.

Derick

-- 

-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Ivan Ristic


  Right, but you can still use shared memory, or, you can store
  persistent objects onto the filesystem. We've done the later
  with satisfactory results.

>

Point taken. But this only allows to share resources that can be copied 
into and from IPC shared memory. Some resources (like open database 
connections, or a JVM) are not like that, even though they are expensive 
to create.

  True.



  Apache 2 resolves this problem. You can configure it to
  run multithreaded. Still, the issue of having a stable PHP remains.


Interesting. Does PHP run with apache 2?


  It depends on who you ask. I haven't tried it myself but from what
  I've read on this mailing list - it works for some people, some
  other people have problems.


Bye,
Ivan



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




Re: [PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Maróy Ákos
Derick Rethans wrote:

Have a look at www.vl-srm.net, and more even the article about it @ 
http://www.vl-srm.net/doc/articles/php-almanac-2002.php (the part about 
Bananas might be th emost relevant thing).

Thanks for the info. Though I could implement a similar deamon in java, 
and call it through XML PRC or other similar way via a network socket. 
(As my original intention was to fire up a JVM and call java functions 
from there.) But using network sockets is far mor expensive than calling 
through JNI. In my case, it seems that such a solution would not worth it.


Akos


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



Re: [PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Derick Rethans
On Thu, 5 Dec 2002, Maróy Ákos wrote:

> Ivan Ristic wrote:
> >   Right, but you can still use shared memory, or, you can store
> >   persistent objects onto the filesystem. We've done the later
> >   with satisfactory results.
> 
> Point taken. But this only allows to share resources that can be copied 
> into and from IPC shared memory. Some resources (like open database 
> connections, or a JVM) are not like that, even though they are expensive 
> to create.

Have a look at www.vl-srm.net, and more even the article about it @ 
http://www.vl-srm.net/doc/articles/php-almanac-2002.php (the part about 
Bananas might be th emost relevant thing).

Derick

-- 

-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Maróy Ákos
Ivan Ristic wrote:

  Right, but you can still use shared memory, or, you can store
  persistent objects onto the filesystem. We've done the later
  with satisfactory results.


Point taken. But this only allows to share resources that can be copied 
into and from IPC shared memory. Some resources (like open database 
connections, or a JVM) are not like that, even though they are expensive 
to create.

  Apache 2 resolves this problem. You can configure it to
  run multithreaded. Still, the issue of having a stable PHP remains.


Interesting. Does PHP run with apache 2?


Akos



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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Ivan Ristic


  From the PHP point of view, you can get problems with persistent
  database connections on a very high load site, that's true. But
  that's about the only problem. Sure, you can't build a persistent
  storage of information in the server but that's a minor issue.

 
It's not a minor issue. Using persistent objects that are expensive to 
aquire is a common pattern, which can improve performance significantly. 
The above scenario prevents exactly that.

  Right, but you can still use shared memory, or, you can store
  persistent objects onto the filesystem. We've done the later
  with satisfactory results.



I guess this is more of an apache issue then a PHP issue. I'd have to 
look more closely at the apache sources to investigate further.

  Apache 2 resolves this problem. You can configure it to
  run multithreaded. Still, the issue of having a stable PHP remains.

  Plus, PHP has no mechanisms to handle multithreaded access from
  user space, you would have to use shared memory locks or file
  system locks.


Bye,
Ivan


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Maróy Ákos
Ivan Ristic wrote:

  From the web serving point of view it isn't. Since Apache usually
  interfaces to all kinds of modules and programs, the fact that
  processes die naturally from time to time helps remove cumulative
  errors.


IMHO this is a last-resort safeguard to prevent a system from falling 
due to badly written applications. But this can not be a reason for 
deciding on the architecture.

  From the PHP point of view, you can get problems with persistent
  database connections on a very high load site, that's true. But
  that's about the only problem. Sure, you can't build a persistent
  storage of information in the server but that's a minor issue.


It's not a minor issue. Using persistent objects that are expensive to 
aquire is a common pattern, which can improve performance significantly. 
The above scenario prevents exactly that.

I guess this is more of an apache issue then a PHP issue. I'd have to 
look more closely at the apache sources to investigate further.

  correctly and handle multithreading - is simply not worth it.


By my measurements, it is worth it.


  (BTW, isn't nsapi the API for the Netscape web server?)


Yes, it is.


Akos



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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Ivan Ristic


  Database connections (and other resources) are persistent on the
  per-server-process level. What this means that an open connection
  in one server process cannot be reused from within another
  server process.


I see. This is sad news indeed.


  From the web serving point of view it isn't. Since Apache usually
  interfaces to all kinds of modules and programs, the fact that
  processes die naturally from time to time helps remove cumulative
  errors.

  From the PHP point of view, you can get problems with persistent
  database connections on a very high load site, that's true. But
  that's about the only problem. Sure, you can't build a persistent
  storage of information in the server but that's a minor issue.


> But is this really a closest one can get

with apache? None of the other extension libraries for apache, like 
nsapi, provides the notion of persistent resources shared among all 
apache requestst?

  No. The only way to do it is to get away from Apache processes
  and use Apache only as an interface to your single process. This
  is how all Java servlet containers do it. Take a look at Jserv
  (called mod_jk these days).

  I once hacked Jserv to work with my C++ application, that was fun.
  It worked (as a single persistent process) but I have found that
  the speed was about the same as the CGI version of the same
  thing (under moderate usage and working with MySQL) that the
  additional trouble of having a different process that you have
  to start and monitor, plus make sure that you free memory
  correctly and handle multithreading - is simply not worth it.

  (BTW, isn't nsapi the API for the Netscape web server?)

Bye,
Ivan


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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-05 Thread Akos Maroy
Ivan Ristic wrote:


How is a persistent database connection handled then? e.g. in the
mysql module?


  Apache 1.x pre-creates a number of server processes. Each process
  handles a certain number of requests (one at a time), and then
  dies. It is then replaced with an another server process. The number
  of processes can vary depending on the load and the configuration.

  Database connections (and other resources) are persistent on the
  per-server-process level. What this means that an open connection
  in one server process cannot be reused from within another
  server process.


I see. This is sad news indeed. But is this really a closest one can get 
with apache? None of the other extension libraries for apache, like 
nsapi, provides the notion of persistent resources shared among all 
apache requestst?


Akos


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



[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-04 Thread Ivan Ristic


How is a persistent database connection handled then? e.g. in the mysql 
module?

  Apache 1.x pre-creates a number of server processes. Each process
  handles a certain number of requests (one at a time), and then
  dies. It is then replaced with an another server process. The number
  of processes can vary depending on the load and the configuration.

  Database connections (and other resources) are persistent on the
  per-server-process level. What this means that an open connection
  in one server process cannot be reused from within another
  server process.

  When using PHP with IIS, on the other hand, you only have one
  process and only one set of persistent connections.

  Since creating a 100% thread safe PHP (PHP meaning the core engine
  plus the libraries) is practically impossible, I would say that
  PHP will go the FastCGI route, even on Windows.

Bye,
Ivan


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




Re: [PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-04 Thread Maróy Ákos
Brad LaFountain wrote:

Are you sure its getting unloaded or is it starting up in another httpd?


I'm not sure which. The only thing I see is that global static variables 
in the shared object have their values re-initialized.


Akos



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



Re: [PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-04 Thread Brad LaFountain

--- Akos Maroy <[EMAIL PROTECTED]> wrote:
> Ivan Ristic wrote:
> >   I do not think that is possible, unless PHP engine itself
> >   is contained within a single process (and runs multithreaded).
> >   Which it isn't (under Apache 1.x & , at least).
> 
> I'm not familiar in general with the PHP engine, so my questions may be 
> quite stupid. Anyway:
> 
> How is a persistent database connection handled then? e.g. in the mysql 
> module?
> 
> looking at the mysql module source code, it seems that there is a list 
> called persistent_list, used in such a manner:
> 
> zend_hash_find(&EG(persistent_list), hashed_details, 
> hashed_details_length+1, (void **) &le
> 
> would this provide some persistnece? If yes, how to use it exaclty? (I 
> couldn't make it work myself.)
> 
> 
> It seems to me that libphp_java.so is unloaded every once in a while. 
> For example, global static variable defined in the module get 
> re-initialized every once in a while. Is this so?

Are you sure its getting unloaded or is it starting up in another httpd?

 - Brad



__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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




[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-04 Thread Akos Maroy
Ivan Ristic wrote:

  I do not think that is possible, unless PHP engine itself
  is contained within a single process (and runs multithreaded).
  Which it isn't (under Apache 1.x & , at least).


I'm not familiar in general with the PHP engine, so my questions may be 
quite stupid. Anyway:

How is a persistent database connection handled then? e.g. in the mysql 
module?

looking at the mysql module source code, it seems that there is a list 
called persistent_list, used in such a manner:

zend_hash_find(&EG(persistent_list), hashed_details, 
hashed_details_length+1, (void **) &le

would this provide some persistnece? If yes, how to use it exaclty? (I 
couldn't make it work myself.)


It seems to me that libphp_java.so is unloaded every once in a while. 
For example, global static variable defined in the module get 
re-initialized every once in a while. Is this so?


I can't see a call to JNI_DestroyJavaVM() anywhere in the java module 
source code. Isn't this a possible reason for resource leaks? Or are 
modules that cleverly unloaded?


Akos


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



[PHP-DEV] Re: persistent java virtual machine under PHP

2002-12-04 Thread Ivan Ristic


What I'm looking for is that the JVM would not be discarded on a regular 
basis, but it would remain persistent.

  I do not think that is possible, unless PHP engine itself
  is contained within a single process (and runs multithreaded).
  Which it isn't (under Apache 1.x & , at least).

  You can perhaps try to use it the other way around, have PHP
  run inside a Java VM. You can also try to get the source code
  for the Java extension from the CVS as some patches have
  been submitted recently.

  Ideal solution for Java integration would be to have a single
  JVM running as a separate process, and to have the PHP communicate
  with it using some efficient protocol. This can be done right
  now although I do not think that the current Java extension
  works like this. However...

  I have "heard" (can someone confirm this, please) that ZE2
  handles foreign (i.e. non-PHP) object nicely and that you
  will be able to have classes and objects that feel like
  normal object but would in fact execute outside the engine.

  If the above is correct I would prefer to wait for ZE2 in
  order to integrate my PHP and my Java. On a similar note,
  is someone working on a ZE2-compatible extension at the
  moment? I might be interesting to work on it.

  There is one relevant project, see http://www.vl-srm.net
  (integrates PHP and PHP, not PHP and Java, but the method
  is the same).

Bye,
Ivan



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