scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 Sockets Handler
2 ===============
3  
4 This handler allows you to write your logs to sockets using [fsockopen](http://php.net/fsockopen)
5 or [pfsockopen](http://php.net/pfsockopen).
6  
7 Persistent sockets are mainly useful in web environments where you gain some performance not closing/opening
8 the connections between requests.
9  
10 You can use a `unix://` prefix to access unix sockets and `udp://` to open UDP sockets instead of the default TCP.
11  
12 Basic Example
13 -------------
14  
15 ```php
16 <?php
17  
18 use Monolog\Logger;
19 use Monolog\Handler\SocketHandler;
20  
21 // Create the logger
22 $logger = new Logger('my_logger');
23  
24 // Create the handler
25 $handler = new SocketHandler('unix:///var/log/httpd_app_log.socket');
26 $handler->setPersistent(true);
27  
28 // Now add the handler
29 $logger->pushHandler($handler, Logger::DEBUG);
30  
31 // You can now use your logger
32 $logger->addInfo('My logger is now ready');
33  
34 ```
35  
36 In this example, using syslog-ng, you should see the log on the log server:
37  
38 cweb1 [2012-02-26 00:12:03] my_logger.INFO: My logger is now ready [] []
39