一、绪

Swoole简介

  • PHP异步网络通信引擎

  • 最终编译为so文件作为PHP的扩展

准备工作

  • Linux环境

  • PHP7 swoole2.1 redis

  • 源码安装PHP7 源码安装swoole

https://www.cnblogs.com/cshaptx4869/p/10395744.html

https://www.cnblogs.com/cshaptx4869/p/10493942.html

https://www.cnblogs.com/cshaptx4869/p/10493933.html

定时器

  • swoole_timer_tick 每隔一定时间执行,毫秒

  • swoole_timer_after 一定时间后执行,毫秒

  • swoole_timer_clear 清除定时器

异步文件系统IO(4.3版本之前)

https://wiki.swoole.com/wiki/page/183.html

  • swoole_async_readfile 异步读取文件内容

    执行顺序:1、先读取文件 2、再执行下码 3、最后执行回调

    读取的文件不能超过4M

  • swoole_async_read

  • swoole_async_writefile

    执行顺序和 readfile 相同

  • swoole_async_write

异步MySQL客户端

https://wiki.swoole.com/wiki/page/517.html

  • 使用场景

    请求文章详情页 -> mysql 文章+1 -> 页面数据展示

异步redis

https://wiki.swoole.com/wiki/page/p-redis.html

进程

https://wiki.swoole.com/wiki/page/p-process.html

进程就是正在运行的程序的一个实例。

内存

https://wiki.swoole.com/wiki/page/245.html

  • Table

    Table一个基于共享内存和锁实现的超高性能,并发数据结构。用于解决多进程/多线程数据共享和同步加锁问题。

  • Atomic

    AtomicSwoole底层提供的原子计数操作类,可以方便整数的无锁原子增减。

协程

https://wiki.swoole.com/wiki/page/p-coroutine.html

二、安装

> wget https://github.com/swoole/swoole-src/archive/v4.3.5.tar.gz

> tar xzvf v4.3.5.tar.gz

> cd swoole-src-4.3.5/

> phpize

> ./configure --with-php-config=/usr/local/php71/bin/php-config --enable-http2 --enable-openssl

> make && make install

> echo 'extension=swoole.so' >> /usr/local/php71/lib/php.ini

> systemctl restart php-fpm.service

如果使用hyperf框架修改php.ini配置文件

swoole.use_shortname = 'Off'

$ php --ri swoole

三、nginx+swoole配置

erver {
root /data/wwwroot/;
server_name local.swoole.com; location / {
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
if (!-e $request_filename) {
proxy_pass http://127.0.0.1:9501;
}
}
} #通过读取$request->header['x-real-ip']来获取客户端的真实IP

四、手册

https://toxmc.github.io/swoole-cs.github.io/

demo: https://www.helloweba.net/tag/swoole.html

CentOS7 安装PHP7的swoole扩展:的更多相关文章

  1. centos7安装PHP7的redis扩展

    前言: 在本篇博客中,我将给大家介绍如何在Centos7上安装PHP-Redis扩展,关于如何在Centos上安装redis的,可以参考另外一篇博客:Centos7安装redis 想要在php中操作r ...

  2. Centos7 安装php7.3 并扩展 MySQL、postgresql

    首先是安装需要的扩展文件 yum -y install freetype-devel yum -y install libpng-devel yum -y install libjpeg-devel ...

  3. CentOS7 安装PHP7的redis扩展:

      phpredis-4.2.0.tar.gz:下载:wget https://github.com/phpredis/phpredis/archive/4.2.0.tar.gz   $ tar -z ...

  4. Centos7 安装PHP7版本及php-fpm,redis ,php-redis,hiredis,swoole 扩展安装

    ============================PHP7.1 ========================================= 1. 更换rpm 源,执行下面两个 rpm - ...

  5. Centos7安装gearman和php扩展

    Centos7安装gearman和php扩展 标签(空格分隔): php,linux gearman所需要的依赖 yum install \ vim \ git \ gcc \ gcc-c++ \ w ...

  6. centos6下安装php7的memcached扩展

    安装php7的memcached扩展 .编译安装libmemcached- wget https://launchpadlibrarian.net/165454254/libmemcached-1.0 ...

  7. window下安装php7的memcache扩展

    安装memcache:http://www.runoob.com/memcached/memcached-connection.html1.4.4 c:\memcached\memcached.exe ...

  8. php----------linux下安装php的swoole扩展

    1.首先你已经安装好了php环境,这里就不介绍php环境的安装了.如果你是编译安装记得将php加入环境变量,以便于方便查看扩展是否安装成功. 2.我安装的php环境缺少了要给东西,详细看下图 如果你没 ...

  9. CentOS7 安装 PHP7.2

    点击查看原文 安装源 安装 EPEL 软件包: $ sudo yum install epel-release 安装 remi 源: $ sudo yum install http://rpms.re ...

随机推荐

  1. css——伪类选择器

    <body> <div class="box">   <p>0</p>         <div>1</div&g ...

  2. js中的局部函数和全局函数的调用

    //局部函数和全局函数的特点 function fc1(){ var name ="chenhao"; function fc2(){ var age = 30; alert(na ...

  3. 「CF894E」 Ralph and Mushrooms

    传送门 Luogu 解题思路 首先我们要发现:在同一个强连通分量里的所有边都是可以无限走的. 那么我们就有了思路:先缩点,再跑拓扑排序. 那么问题就是 \(\text{DP}\) 状态如何初始化. 我 ...

  4. html 标签 frame

    html 标签 frame 对于html标签,一般都是在<html>标签对里包着<head>标签对和<body>标签对,body元素定义文档的主体,包含文档的所有内 ...

  5. VUE 鼠标右键自定义

    需要在区域内右击自定义菜单的DIV绑定contextmenu右击事件 <div   style="width:100% ; z-index: inherit;position: rel ...

  6. 【SSM】AppFileUtils

    11 package com.kikyo.sys.utils; import java.io.File; import java.io.IOException; import java.io.Inpu ...

  7. .hpp 文件

    .hpp 是 Header Plus Plus 的简写,是 C++程序头文件. 其实质就是将.cpp的实现代码混入.h头文件当中,定义与实现都包含在同一文件,则该类的调用者只需要include该hpp ...

  8. if 条件的 true / false 及 select 的值

    if 条件的 true / false 任何不是 false, undefined, null, 0, NaN 的值,或一个空字符串('')在作为条件语句进行测试时实际返回true,因此您可以简单地使 ...

  9. idea通过Ctrl+鼠标滚轮放大/缩小字体

  10. Git三招

    一.Git提交指令 git init git第一次使用在当前文件夹初始化一个git仓库,第二次不需要 git add . 把当前文件夹所有文件添加到缓存区中. 可以选特定的文件夹或文件.将后面的.改变 ...