Giter Site home page Giter Site logo

phplogger's Introduction

phplogger

Logging classes for PHP, client server approch to limit I/O and CPU. Currently used to write to log files, but could be expanded write to other back ends. We also use this for other non PHP software with the PHP log_receiver.php

Problem to Solve

We had some projects in PHP that needed to write to log files, we tried several methods.

  1. Use error_log, this writes to webserver errorlog, seems to be fine except you have to parse the data from the errorlog, and could not write different log files for different modules.

  2. Open a file, append a line, close the file; this works well and gives you flexablity of writing multiple logs, and cycling logs. The downside is that this is I/O intensive and can cause performance problems in heavy used servers. You also have to deal with file locking and waiting for other processes.

This Solution

This solution uses 2 pieces, a client side writer component that is included in a project, and a reader component that is run standalong as a background process. The client component communicates to the reader component via UDP over localhost (though remote hosts could be possible). The reader component batches up the writes for a particular file or resource and flushes them out at a settable interval. The client side also has some control on when the logs are flushed.

Sending the logs over UDP has several interesting advantages. First there is little impact on the client side, UDP sockets should be setup to not block, if the buffer or the network is not ready, the logs just get tossed, no waits are put on the sender. Second, on the reciever side, you can dynamically filter, or not log at all until you need to. If you choose not to listen to the UDP traffic, it just goes away. If you are receiving the UDP traffic, you can filter what you want to log, no need to change the running client code.

How it Works

The client side sends log messages to the reader component via UDP datagrams by default on port 1025. The datagrams are in the following format:

[$cmd] [$filename] [$timestamp] [rest of line message to log]

where:

$cmd is L for log and F for flush.
$filename is the filename to log to or flush, if flush * is acceptable
$timestamp to use for log

The rest of the line is the message to log.

How to Use

For now see the example test_log_server.php for the reader component and test_send_log.php for the writer component.

License

phplogger's People

Contributors

lowerpower avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.