Libevent 是一個(gè)用C語(yǔ)言編寫(xiě)的、輕量級(jí)的開(kāi)源高性能I/O框架,支持多種 I/O 多路復(fù)用技術(shù): epoll、 poll、 dev/poll、 select 和 kqueue 等;支持 I/O,定時(shí)器和信號(hào)等事件;注冊(cè)事件優(yōu)先級(jí)。PHP提供了對(duì)應(yīng)的擴(kuò)展 libevent、 Event 。
相比 libevent ext, event ext 擁有更好的性能表現(xiàn)和更全面的API,可以讓我們更友好的使用 Libevent。
安裝 Libevent 庫(kù)
php event 擴(kuò)展 依賴 Libevent 庫(kù),需要先編譯安裝(注意是 Libevent 庫(kù),非 libevent 擴(kuò)展)。
git clone --depth=1 https://github.com/nmathewson/Libevent.git cd Libevent ./autogen.sh ./configure --prefix=/usr/local/libevent make && make install
安裝 Event 擴(kuò)展
可以直接使用 pecl
安裝
pecl install event downloading event-2.5.3.tgz ... Starting to download event-2.5.3.tgz (140,913 bytes) ..............................done: 140,913 bytes 50 source files, building running: phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 Enable internal debugging in Event [no] : Enable sockets support in Event [yes] : libevent installation prefix [/usr] : /usr/local/libevent ... Build process completed successfully Installing '/usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/event.so' install ok: channel://pecl.php.net/event-2.5.3 Extension event enabled in php.ini
查看安裝結(jié)果
[root@localhost ~]# php --ri event event Event support => enabled Sockets support => enabled Debug support => disabled Extra functionality support including HTTP, DNS, and RPC => enabled OpenSSL support => enabled Thread safety support => disabled Extension version => 2.5.3 libevent2 headers version => 2.2.0-alpha-dev
推薦:《PHP7教程》