1 , Libevent Introduction
2 , Why to learn libevent
3 , Php libevent expansion Module Installation
1, libevent Introduction
libevent is an event-triggered network library for Windows ,linux ,FreeBSD multiple platforms, internal use Select ,poll ,epoll ,kqueue such as system invoke management event mechanism. Libevent is cross-platform and has extraordinary performance. and Nodejs the same as the event-driven; Official website:http://libevent.org/
The latest stable version
Https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
Main modules:
Event Processing Framework
Event Engine Module
Buffer Management module
Signal Processing Module
PHP does not natively support multi-threading,php The concurrency mechanism cannot be implemented well. Pecl provided by Pcntl (Process Control),libevent extensions,sockets package,stream system functions, you can use php easy to develop high-performance, high-concurrency network applications.
Simple Application Example:pcntl fork N a worker . Master Process After the request is received, processing information is sent to the worker program ,worker back to client when finished processing . Master Process can be followed by the amount of concurrency, to set the worker The number , i.e. n the size, and monitor (monitoring)worker data and start more processes when they are insufficient. With nginx principle.
attached:Php Network Programming Framework
Http://code.google.com/p/swoole/downloads/list
2, Why to learn libevent
http server can be said libevent libevent http http server socket processing and http protocol processing winding.
Learning libevent help to improve the programming skills, in addition to network program design,Libevent The code has a lot of useful design techniques and basic data structures, such as information hiding, function pointers,C Language polymorphism support, lists and heaps, and so on, all help to improve their own program skills [1 ] .
There are three types of processing for requests:
1. Connection Input fork a new process
2. Connection Input pthread_create
3. connection input throw a event-based array; main process do nonblocking things;
3, Php libevent expansion module installation
Curl–o https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
TAR–ZXVF libevent-2.0.16-stable.tar.gz
Cd libevent-2.0.16-stable
/usr/local/php/bin/phpize
./configure
Make
Make install
Vi/usr/local/php/etc/php.ini
Extension_dir= "";
Extension=libevent.so
Php–m | grep Lib
Installation Successful
PHP Libevent Extension