ofrommel
ofrommel

Reputation: 2177

Globally autoloading class

Is there a way to globally load a class for all PHP scripts in a specific installation? Or, in other words, extend the PHP interpreter to provide a class globally? My intention is to build a centralized logging facility for all PHP web applications on a server, but I don't want to repeat calling require(), use and Autoloader statements in every script.

It would be even better to have a global logging object available in every script, but that would require to have some kind of thread-safe object and/or locking.

Any ideas?

Upvotes: 1

Views: 50

Answers (1)

ofrommel
ofrommel

Reputation: 2177

From the comments I understand that the best way to achieve this is to write a PHP extension that implements the class so it's available in all scripts on a server. Additonally I found an extension called "php-logger-extension" that does exactly that:

"By using the php_logger the application just need to load the extension once, this is done when the web server is initialized, also the application does not need to parse any php classes in order to be able to log."

https://code.google.com/p/php-logger-extension/

Upvotes: 1

Related Questions