PHP Libevent Extension

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.