Hi
I am currently developing a kind of application server based on PHP
language.
I use modifications I made on SAPI embed/.
I use threads massively.

In my application design, every thread can load different PHP modules. In
practise, modules are loaded just before php_request_startup() and they are
unloaded after php_request_shutdown()

The problem I face is that I randomly receive PHP warnings :
<br />
<b>Warning</b>:  Module 'X7V3' already loaded in <b>Unknown</b> on line
<b>0</b><br />
<br />
<b>Warning</b>:  Function registration failed - duplicate name -
XXXXXXXXXXXXXXXXXX in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  X7V3:  Unable to register functions, unable to load in
<b>Unknown</b> on line <b>0</b><br /

I looked at Zend/zend_API.c and I realized that 2 variables, "module_count"
and "module_registry", are not thread safe and that there is a comment
recomending mutex use for these 2 variables.

I had asked for a Feature/Change request on bugs.php.net (#40668) but it has
been closed :s

Then I learnt (thank you Tony) that dl() function is deactivated in  ZTS
mode and I also learnt from Tony that this kind of problem was not a
priority ...

I think it is important to settle this problem at least for IIS and Apache
Threadpool/Worker servers.

At last, I would like to share my view on ZTS vs mutex use :

Mutex :
pros : uses slightly less memory
cons : does not give possibility to create module spaces by thread - uses
more processor resource (as there is a mutualized lock for various threads)

ZTS :
pros : possibility to create module spaces - less processor
cons : slight impact on memory

This is why I propose to use a ZTS resource instead of mutex to make
"module_registry" thread safe.

The use of ZTS resources will give a thread the ability to have its own
module HashTable.

In both cases (mutex or ZTS resource), we will be able to reactivate the
dl() function in ZTS mode.

I propose to develop the ZTS version resource. Or shall I let you do it ?

Kind regards

Michael Vergoz 

Reply via email to