Oldukça istekleri (you could serialize it and store it in a file or something like that, and un-serialize it when another requests comes ; but that's not really the way things are generally done) arasında etrafında bazı nesneyi tutmak anlamına gelir - PHP ile her isteği farklı bir işlem tarafından işlenir
Bu PHP script istek aldığında her zaman, yeniden instanciate logger'inizi zorunda kalıyoruz.
Now, if you want to use your logger from several different classes/methods/functions in the same script, you have to know that variables are not global "by default" in PHP : a variable declared outside of a function is not accessible from inside a function, unless you said so using the global keyword.
In this kind of situation, when you want one and only one instance of a specific class (your logger) available from anywhere in your application, people often use the Singleton Design Pattern.
Bu gibi bir şey kullanmak için izin verirsiniz:
My_Logger_Class::log('blah');
Kodunuzun herhangi bir kısmı, ve log
yöntemi ile ilgileneceğiz:
- sınıf instanciating Zaten bir varolan örneği yoktu eğer
- Giriş gerçek
Ve, evet, bu yöntem bir HTTP isteği denir ilk kez, yeniden açmak günlük dosyası (if logging to a file) gerekecek.
As a sidenote : there are already some existing great logging components, like PEAR::Log
or Zend_Log
.
Belki bunlardan birini kullanarak bazı tekerleği yeniden icat daha az zaman harcamak yardımcı olabilir?