PHP脚本执行和多线程环境(PHP5扩展)

I need some clarification executing a "class" that is implemented as a PHP 5 module. The class has a few methods including constructor/destructor and in a PHP script I can use it as follows:


<?php
// --- construct 
$c = new my_class("some argument");

// --- add data
foreach ($arr_of_elements as $k => $v) {
    $c->add_element($v);
}
// --- execute algorithm
$c->execute();

// --- get result as xml format
$result = $c->get_result_as_xml();
// --- end of script (destruct)
?>

My question is: When a request is made is the above script executed in a single thread within the PHP module of the Apache2 server? In my opinion it should.

I am asking this, because I implemented a PHP5 extension in C that uses the Java JVM with some JNI code, so when above script is executed it attaches to the JVM with the class constructor, calls the methods (which are actually wrappers for my JNI Calls) and detaches from the JVM with the destructor. Executing Apache in debugging mode (using -X), the and script runs like a charme, multiple runs (reloading) makes no problem at all, but Apache2/PHP in regular multi-process mode, after a few calls the JNI AttachCurrentThread to the JVM hangs. I try to track down that issue to find a solution.

Is there s possibility to get some information in which thread (id, or such) I am executing?

I need to make sure that the execution is a single thread execution.

I am using Apache2 with PHP 5.2.16 (compiled from source) on Ubuntu Lucid 10.04 LTS

If something is unclear, please let me know. Thanks for the info and help!

Andreas

If you've got apahce2 in the recommended for php prefork() configuration with modphp. Then each http request will be running in its own http process with a single php thread per process. I suspect you are running in one of the other modes.

If your not using prefork configuration a few of the php functions that wrap c libraries will start busting as they are not thread safe, including your custom java code mentioned above.

There are also a couple of fastcgi configurations that work slightly diffrently than modphp.