# Asymmetric Module Init / Deinit

- Thread: https://externals.io/message/34828
- Original archive: https://news-web.php.net/php.internals/34828
- Started by Michael B Allen on 2008-01-18T07:46:25+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #34828 — Michael B Allen — 2008-01-18T07:46:25+00:00

URL: https://externals.io/message/34828#34828

I have someone using my extension who is seeing some strange behavior
where the module initializes which Apache starts, the extension works
perfectly and then, without warning, after about 40 seconds, the
deinitialization routine runs. This kills some state in a global
context and everything goes very badly from there. Otherwise, Apache
is still running just fine.

The setup is Apache 2.2 / PHP 5.2 on Fedora 7.

I personally have not been able to replicate this problem but I'm
thinking it must be an Apache worker exiting that's triggering deinit.
I know Apache 1.x has that behavior and I'm wondering if anyone knows
if 2.2 exhibits that behavior. It's annoying because it means that the
module initialization is called once whereas the deinitialization
routine is called many times.

Does this sound familiar to anyone?

I would appreciate any insight as to how I can ensure that my module
is deinitialized only once. My first thought is to simply save the pid
of the process that initialized the module and check for it in the
deinitialization routine.

Mike

---

## #34829 — Scott MacVicar — 2008-01-18T10:25:30+00:00

URL: https://externals.io/message/34828#34829 · In reply to: #34828

Apache children get killed and re-spawned after the number of requests 
defined by MaxRequestsPerChild, the default is 10,000. Though MINI 
talways get called for each child spawned.

Is Apache using pre-fork or worker?

Scott

Michael B Allen wrote:
> I have someone using my extension who is seeing some strange behavior
> where the module initializes which Apache starts, the extension works
> perfectly and then, without warning, after about 40 seconds, the
> deinitialization routine runs. This kills some state in a global
> context and everything goes very badly from there. Otherwise, Apache
> is still running just fine.
> 
> The setup is Apache 2.2 / PHP 5.2 on Fedora 7.
> 
> I personally have not been able to replicate this problem but I'm
> thinking it must be an Apache worker exiting that's triggering deinit.
> I know Apache 1.x has that behavior and I'm wondering if anyone knows
> if 2.2 exhibits that behavior. It's annoying because it means that the
> module initialization is called once whereas the deinitialization
> routine is called many times.
> 
> Does this sound familiar to anyone?
> 
> I would appreciate any insight as to how I can ensure that my module
> is deinitialized only once. My first thought is to simply save the pid
> of the process that initialized the module and check for it in the
> deinitialization routine.
> 
> Mike

---

## #34830 — Michael B Allen — 2008-01-18T15:51:14+00:00

URL: https://externals.io/message/34828#34830 · In reply to: #34829

> Apache children get killed and re-spawned after the number of requests
> defined by MaxRequestsPerChild, the default is 10,000. Though MINI
> talways get called for each child spawned.
>
> Is Apache using pre-fork or worker?

Pre-fork.

That's weird. I set MaxRequestPerChild to 100, ran ab -n 500 url and I
can see workers being destroyed and created but I only see MINIT being
called once on startup. As workers exit I see MSHUTDOWN but no
corresponding MINIT. Just to be sure my log apparatus wasn't setup yet
I wrote a message to stderr, flushed it and verified that it's in the
Apache error_log.

I'm pretty sure MINIT gets called on startup and MSHUTDOWN gets called
every time a child exits.

I used stock Apache 2.2.6 and PHP 5.2.5 with the standard Apache 2
build instructions [1] (although I did not compile php --with-mysql)
on x86_64-redhat-linux.

Mike

[1] http://www.php.net/manual/en/install.unix.apache2.php

> Michael B Allen wrote:
> > […]
>


-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/
