php Günlüğü Sorunlar

2 Cevap php

Kod burada bir sorun olduğu gerçeği dışında, çalışıyor:

 //Log Events
function logEvent($newinput) {
    if ($newinput !== NULL) {
        // Add a timestamp to the start of the $message
        $newinput = date("Y/m/d H:i:s").': '.$newinput;
        $fp = fopen('log.txt', 'w');
        fwrite($fp, $newinput."\n");
        fclose($fp);
    }
}
//Problem writing these two lines to log.txt?
 //The bad, the two lines below are not on the log.txt
logEvent('Selection'.$selections[$selection]);
logEvent('Change' . $change. 'cents.');

//This line is written to a text file (log.txt), okay that's good.
logEvent('Input' .  $newinput);

2 Cevap

ben bunu yeniden yazıyoruz, dosyaya ekleme değil düşünüyorum. 'a' yerine 'w' ve fopen deneyin.

Dosyayı açarken append değiştirici kullanmak gerekir, sen gittin

fopen ('log.txt', 'w');

Bu yerine kullanıldığında eğer bu işlev çağrısı, her zaman, günlük dosyası, şişmiş ve yeniden oluyor demektir

fopen ('log.txt', 'a');

sonra yeni günlük girişleri yerine dosyaya ekler.

Ayrıca, çok daha sonra uçlar için dosyayı açık tutarak içine bakmak olabilir, ancak diğer istekleri birden güncellemeleri ile sorunlar olabilir.