Before log is printed in a document, then open the folder, and finally open the document to see what is inside, every time to open the folder feeling very annoying.
Some days ago I saw colleagues develop. NET, it is very convenient to use one of his own gadgets to view the contents of the log at all times, so I want to migrate to PHP development.
First, view the effect
1, open the client gadget Mylog.exe, enter localhost in the address, port input 5555, click the Start link, the next screen will display the word "start listening".
2, open the log.php page, the page is very simple, printed a string of characters.
3, view Mylog.exe, inside has received the Hello string
Second, PHP code
1) to download a PHP version of the Zmq.dll file first
1. Open the link http://pecl.php.net/package/zmq and click on a version of the DLL.
2. Then set in php.ini
3, log.php in the code, note: Here is the use of Publish-subscribe mode, from PHP to publish,client small tools to do subscribe, is the relationship between the two.
<? PHP $context New Zmqcontext (); $publisher $context->getsocket (ZMQ::socket_pub); $publisher->bind ("tcp://*:5555"); Sleep (1); $publisher->send (' hello '); Echo ' Sent Hello ';? >
Third, the client code
1, a total of two files, the client is can directly run EXE file, MyLog is. NET source code, edited with VS2010. Open the client file and just click Mylog.exe to open the gadget.
2. Clrzmq.dll is a ZMQ auxiliary DLL file in. NET and needs to be introduced into the source code.
3, in the client do ZMQ sub operation, receive and print out the data.
voidLogreceiver () {using(Zmqcontext CTX =zmqcontext.create ()) { using(Zmqsocket sub =CTX. Createsocket (sockettype.sub)) {SUB. Connect ("tcp://"+ Address. Text +":"+Port. Text); Sub. Subscribeall (); Sub. Receiveready+ = (s, e) = = { stringLog =Sub. Receive (Encoding.UTF8); Handlelog (log); }; varPoller =NewPoller (NewList<zmqsocket>{sub}); while(_recvgo) {Try{poller. Poll (); } Catch(Exception ex) {}}} } }
There are still a lot of problems in integrating into the actual project, and I'm just going to show you a simple demo.
Demo Download:
http://download.csdn.net/detail/loneleaf1/7981505
Resources:
HTTP://ZEROMQ.ORG/ZMQ Home
HTTP://PECL.PHP.NET/PACKAGE/ZMQ php dll download
Study and study of Http://news.cnblogs.com/n/154000/ZMQ
HTTPS://GITHUB.COM/ZEROMQ/CLRZMQ clrzmq-official 0MQ Bindings for. NET and Mono
PHP Log always view gadgets