Project: moodle
Issue MDL-42040: Organize the registration of shutdown handlers
This issue arrived because, recently I've started to get some "$DB not available" messages when profiling pages, leading to the profiling runs not sent to DB. And I'm pretty sure that it has been working ok since 2.0, until we introduced the new sessions stuff that changed the internal order of those handlers. So please, avoid arguing things like "it should not be using $DB" and friends (I'm aware of them). It worked and now it does not. Let's try to improve the situation and the future. Right now the registration of shutdown handlers (register_shutdown_function) is completely chaotic and disorganized, and that can lead to more and more problems where some objects, not available anymore, or disposed by a previous handler are needed later in the chain of shutdowns. {code} grep -lr register_shutdown_function * {code} So we need some method to organize and force their registration in an ordered way, declaring their needs (DB, logging, whatever) and observing any dependencies between them and also, surely containing references to all the needed used to avoid its auto-disposal by php. Not sure how to encapsulate all that information (needs, dependencies, disposal) nor how to behave (multiple handlers vs a big one in charge of everything). But it should be computable, I hope. Ciao :-)
Story points: 4