一、绪

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. 动态规划: 最大m子段和问题的详细解题思路(JAVA实现)

    这道最大m子段问题我是在课本<计算机算法分析与设计>上看到,课本也给出了相应的算法,也有解这题的算法的逻辑.但是,看完之后,我知道这样做可以解出正确答案,但是我如何能想到要这样做呢? 课本 ...

  2. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用隐藏层

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  3. Codeforces Round #621 (Div. 1 + Div. 2) C. Cow and Message

    Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is ...

  4. 线程池ExecutorService的使用及其正确关闭方法

    创建一个容量为5的线程池 ExecutorService executorService = Executors.newFixedThreadPool(5); 向线程池提交15个任务,其实就是通过线程 ...

  5. 【SSM 验证码】登录验证码

    LoginController /** * 登陆方法 */ @ResponseBody @RequestMapping("login2") public Map<String ...

  6. cmake 环境安装与使用

    CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的 ...

  7. [ DLPytorch ] 注意力机制&机器翻译

    MachineTranslation 实现过程 rstrip():删除 string 字符串末尾的指定字符(默认为空格). 语法:str.rstrip([chars]) 参数:chars -- 指定删 ...

  8. 「JSOI2014」矩形并

    「JSOI2014」矩形并 传送门 我们首先考虑怎么算这个期望比较好. 我们不难发现每一个矩形要和 \(n - 1\) 个矩形去交,而总共又有 \(n\) 个矩形,所以我们把矩形两两之间的交全部加起来 ...

  9. Python开发:Python运算符

    运算符 1.算数运算: 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 -10 * 乘 - 两个数相乘或是返 ...

  10. extractvalue报错注入

    查看源码 $uagent = $_SERVER['HTTP_USER_AGENT']; ………… $uname = check_input($_POST['uname']); $passwd = ch ...