一、绪

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. EF中 GroupJoin 与 Join

    数据: GroupJoin: 返回左表所有数据 using (tempdbEntities context = new tempdbEntities()) { var query = context. ...

  2. QAction菜单行为

    /*File*/ QAction* close_action_; /*File*/ QAction* close_action_;

  3. 杭电 1114 Piggy-Bank 完全背包问题

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. 软件版本 Alpha、Beta、Rc

    软件版本的周期 α.β.γ 表示软件测试中的三个阶段 α :第一阶段,内部测试使用 β: 第二阶段,消除了大部分不完善的地方,仍可能存在漏洞,一般提供给特定的用户使用 γ: 第三阶段,产品成熟,个别地 ...

  5. PostgreSQL数据库-分页sql--offset

    select * from users order by score desc limit 3;--取成绩的前3名=====select * from users order by score des ...

  6. Mac 系统上有趣的插件

    1.微信小助手:https://github.com/TKkk-iOSer/WeChatPlugin-MacOS 作用:开启消息撤回拦截,设置自动回复,远程登录Mac,微信多开,免认证登录.... 2 ...

  7. JS获取光标在input 或 texterea 中下标位置

    <textarea placeholder="请输入表达式" id="methodInput" ></textarea> 获取位置: v ...

  8. mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or directory)

    mysqld: Can't change dir to 'D:\TONG\mysql-5.7.19-winx64\data\' (Errcode: 2 - No such file or direct ...

  9. mybatis=<>的写法

    第一种写法(1): 原符号 < <= > >= & ' "替换符号 < <= > >= & &apos; " ...

  10. redhat 7.6 流量监控命令、软件(1) ethstatus

    1. 查看1个月内流量,只保留一个月的流量 命令: sar   -n  DEV   -f    /var/log/sa/sa26 RX代表进来的流量,TX代表出去的流量 2.安装查看实时流量软件eth ...