开发者

php logging all events of an application scripted in php

What do php geeks, professionals, and all others us to log their flat files.开发者_如何学Go

Are there functions that can just log one .php page?

Can the logging in php be controlled?

On a side-note, anyone used this for logging? [http://www.monperrus.net/martin/phpmodlog][1]

Apparently my first question was not clear...


You could create a function that uses fwrite to write your events to a log file.

eg:

function logEvent($message) {
    if ($message != '') {
        // Add a timestamp to the start of the $message
        $message = date("Y/m/d H:i:s").': '.$message;
        $fp = fopen('/path/to/log.txt', 'a');
        fwrite($fp, $message."\n");
        fclose($fp);
    }
}

You should also add checks that the file is writeable, which you can find code for on the fwrite page.

For each of the events that you mention, you can then do:

// Log that user has started playing
logEvent('User '.$user.' has started playing Battleships.');

Expand it to include/do whatever you want.

Edit: You've edited your question, but I'll leave my answer here because you may find it useful. As others have mentioned though, you really can't reliably tell when someone has closed the browser window. Also changed to append rather than override.


If you are on PHP5 then you could look at using sqlite, which stores information in a text file.

Might take you some time to work it out but you could also look at using the library at PEAR::Log which provides a very simple logging mechanism.

http://pear.php.net/package/Log


What do you mean by has finished playing? How do you define that. Without JS there is no posibility to know when a user leaves the page.

But you would have to elaborate on what you pricesely mean by those events to give you advice.

The most accurate you can be is logging everytime a user hits a page. And then when a certain time is passed without activity, the user stopped playing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜