PHP 7.1.10 (cli) (built: Oct 9 2017 10:44:28) ( NTS )
1.安装http2
a.下载 nghttp2, 解压 sudo tar -zxvf nghttp2-1.32.0.tar.xz
b.进入目录 nghttp2-1.32.0
sudo ./configure
sudo make && make install
2.安装hiredis
a.下载hiredis 解压 sudo tar -zxvf hiredis-0.13.3.tar.gz
b.进入目录hiredis-0.13.3,执行 sudo make -j && sudo make install
3.安装swoole4.0
a.下载swoole 4.0 sudo wget https://pecl.php.net/get/swoole-4.0.1.tgz
b.进入swoole目录,执行命令 /usr/local/php/bin/phpize
c.编译 sudo ./configure \
--with-php-config=/usr/local/php/bin/php-config \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd
4.0.1或更高版本去除了--enable-coroutine编译选项, 改为动态配置
enable_coroutine动态配置请见文档
enable_coroutine 选项相当于在回调中关闭以前版本的SW_COROUTINE宏开关, 关闭时在回调事件中不再创建协程,但是保留用户创建协程的能力。
当enable_coroutine设置为true时,底层自动在onRequest回调中创建协程,开发者无需自行使用go函数创建协程
当enable_coroutine设置为false时,底层不会自动创建协程,开发者如果要使用协程,必须使用go自行创建协程,如果不需要使用协程特性,则处理方式与1.x是100%一致的
注意:在b这一步,哪里出错就安装那里,假如openssl没有就安装openssl,然后查看ls /usr/local/include/openssl 有无,
没有就ln -s /usr/local/openssl/1.0.2o_1/include/openssl /usr/local/include/ (建立软连接过去就可以了)
d.安装:sudo make && make install
e.查看php -m (查看php扩展)
root1@ubuntu:/opt/swoole-4.0.1$ php --ri swoole
swoole
swoole support => enabled
Version => 4.0.1
Author => tianfeng.han[email: mikan.tenny@gmail.com]
coroutine => enabled
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async redis client => enabled
async http/websocket client => enabled
sockets => enabled
openssl => enabled
http2 => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
下载 4.0