Table of Contents
客户端
服务器端
多端口多协议示例:
其他
问题修复
移除特性
Home Backend Development PHP Tutorial swoole-1.8.0 发布,PHP 的异步并行 C 扩展

swoole-1.8.0 发布,PHP 的异步并行 C 扩展

Jun 20, 2016 pm 12:38 PM

Swoole-1.8.0 版本已发布,此版本是一个里程碑式新版本,新增了多项新特性、多项核心功能优化以及问题修复、移除了无效的特性。更新内容如下:

客户端

  • 增加原生异步 MySQL 客户端

  • 增加原生异步 Redis 客户端,基于 Redis 官方提供的 hiredis 库

  • 增加原生异步 Http 客户端

  • 增加原生异步 WebSocket 客户端支持

  • 重构底层 swClient,异步 TCP 客户端实现放到 swoole 内核中

  • 增加 swoole_client->reuse 属性,SWOOLE_KEEP 长连接模式下标识是否为复用的连接

服务器端

  • 重构 websocket 服务器代码,底层与 length_check 协议复用相同的处理函数,增强稳定性

  • 增加 Task 进程对 tick/after 定时器的支持,底层基于高精度的 setitimer+ 信号实现

  • 保存构造函数中传入的 host、port 参数到 swoole_server 对象属性

  • 增加多端口多协议的支持(重要更新)

  • 增加 swoole_server->defer 函数用于延时执行一些函数

  • 增加 swoole_server->close 强制切断连接的选项,设置第二个参数会 true 会清空发送队列并立即切断连接

多端口多协议示例:

$serv = new swoole_server("0.0.0.0", 9501);$port2 = $serv->listen('127.0.0.1', 9502, SWOOLE_SOCK_TCP);$port2->set(array(    'open_length_check' => true,    'package_length_type' => 'N',    'package_length_offset' => 0,       //第N个字节是包长度的值    'package_body_offset' => 4,       //第几个字节开始计算长度    'package_max_length' => 2000000,  //协议最大长度));$port2->on('receive',  function (swoole_server $serv, $fd, $from_id, $data)  {    echo "ServerPort2\n";});$serv->on('connect', function ($serv, $fd, $from_id){    echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n";});$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {    echo "[#".$serv->worker_id."]\tClient[$fd]: $data\n";    if ($serv->send($fd, "hello\n") == false)    {        echo "error\n";    }});$serv->on('close', function ($serv, $fd, $from_id) {    echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Close.\n";});$serv->start();
Copy after login

其他

  • 增加swoole_table对key值的存储,foreach遍历table时可以获取到key值

  • 更改swoole_table的key对比模式,从crc32比对改为直接进行字符串对比

  • 更新utlist.h库到1.9.9版本

swoole_table保存Key值会增加内存占用,如table的size为100万,KEY值存储会增加64M内存占用

问题修复

  • 修复启用消息队列后发生double-free问题

  • 重构定时器,修复after、tick定时器偶然出现的core dump的问题

  • 定时器使用最小堆数据结构,插入/删除时间复杂度为log(N)

  • 修复swoole_process::signal在PHP7下发生core dump的问题

  • 修复swoole_async_write在PHP7下发生core dump的问题

移除特性

  • 移除未支持的特性相关历史遗留代码,如heartbeat_ping、dispatch_key_type等

  • 移除swoole_server->addtimer、swoole_server->deltimer、swoole_server->gettimer

  • 移除swoole_timer_add、swoole_timer_del

  • 移除swoole_server的onTimer事件

  • 移除task_worker_max配置及相关特性代码

  • 移除swoole_server->handler方法

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles