How to install Libevent extension for PHP

醉折花枝作酒筹
Release: 2023-03-11 06:24:01
forward
1922 people have browsed it

libevent is an event-triggered network library, suitable for windows, linux, freebsd and other platforms. It internally uses system calls such as select, poll, epoll, kqueue and other system calls to manage event mechanisms. Let’s learn with the editor how to install the Libevent extension.

How to install Libevent extension for PHP

1. Introduction to libevent

libevent is an event-triggered network library, suitable for windows, linux, freebsd and other platforms. It uses select, System calls such as poll, epoll, and kqueue manage event mechanisms. Libevent is cross-platform and has extraordinary performance. It is event-driven like nodejs; official website: http://libevent.org/

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 itself does not support multi-threading, and php cannot implement the concurrency mechanism very well. The pcntl (process control), libevent extension, socket package, and stream system functions provided by Pecl can easily develop high-performance, high-concurrency network applications using PHP.

Simple application example: Pcntl fork n workers. After the master process gets the request, the processing information is sent to the worker program, and the worker sends it back to the client after processing. Master process can set the number of workers, that is, the size of n, according to the amount of concurrency, and monitor the data of workers, and start more processes when there is insufficient. Same as nginx principle.

Attachment: Php network programming framework

http://code.google.com/p/swoole/downloads/list

2. Why should you learn libevent

http server can be said to be a classic application of libevent. You can find the standard writing method of http from libevent. The non-blocking http server is the intertwining of socket processing and http protocol processing.

Learning libevent can help improve your programming skills. In addition to network programming, Libevent's code has many useful design techniques and basic data structures, such as information hiding, function pointers, and polymorphism in C language. Support, linked lists, heaps, etc., all help to improve one's programming skills [1].

Three types of request processing:

  • connection input fork a new process

  • connection input pthread_create

  • connection input throw a Event-based array; main process do nonblocking things;

3. Php libevent extension 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
Copy after login

Installation successful

Recommended learning:php Video tutorial

The above is the detailed content of How to install Libevent extension for PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:imooc.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template