Skip to content

Commit

Permalink
update swoole4.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy918 committed Nov 6, 2018
1 parent 3b8384e commit 8bb82a8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ RUN apt-get update && apt-get install -y \
zlib1g-dev \
vim \
libssl-dev \
libpcre3 \
libpcre3-dev \
libnghttp2-dev \
unzip \
wget \
make \
supervisor \
--no-install-recommends \
&& docker-php-ext-install zip opcache bcmath pdo_mysql \
&& cd /home && rm -rf temp && mkdir temp && cd temp \
&& wget https://github.com/swoole/swoole-src/archive/v2.1.3.tar.gz \
&& wget https://github.com/swoole/swoole-src/archive/v4.2.6.tar.gz \
https://github.com/redis/hiredis/archive/v0.13.3.tar.gz \
https://github.com/phpredis/phpredis/archive/3.1.3.tar.gz \
https://github.com/msgpack/msgpack-php/archive/msgpack-2.0.2.tar.gz \
Expand All @@ -32,7 +35,7 @@ RUN apt-get update && apt-get install -y \
#解压安装包
&& tar -xzvf 3.1.3.tar.gz \
&& tar -xzvf v0.13.3.tar.gz \
&& tar -xzvf v2.1.3.tar.gz \
&& tar -xzvf v4.2.6.tar.gz \
&& tar -xzvf msgpack-2.0.2.tar.gz \
&& tar -xzvf 2.0.0.tar.gz \
&& tar -xzvf igbinary-2.0.5.tgz \
Expand All @@ -48,8 +51,8 @@ RUN apt-get update && apt-get install -y \
&& cd /home/temp/hiredis-0.13.3 \
&& make -j && make install && ldconfig \
#源码编译swoole, 注意先往环境请去除--enable-swoole-debug配置
&& cd /home/temp/swoole-src-2.1.3 \
&& phpize && ./configure --enable-swoole-debug --enable-async-redis --enable-openssl --enable-coroutine \
&& cd /home/temp/swoole-src-4.2.6 \
&& phpize && ./configure --enable-mysqlnd --enable-openssl \
&& make && make install \
#源码编译安装inotify
&& cd /home/temp/php-inotify-2.0.0 \
Expand Down Expand Up @@ -96,7 +99,7 @@ RUN apt-get update && apt-get install -y \
&& echo extension=swoole.so>swoole.ini \
&& echo extension=msgpack.so>msgpack.ini \
&& echo extension=ds.so>ds.ini \
&& echo extension=protobuf.so>protobuf.ini \
&& echo extension=protobuf.so>ds.ini \
#添加系统配置,例如php.ini,opcache-recommended.ini
&& echo memory_limit = 1024 >> php.ini \
&& echo Mdata.timezone = "Asia/Shanghai" >> php.ini \
Expand Down
22 changes: 22 additions & 0 deletions bin/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
$server = new swoole_websocket_server("0.0.0.0", 9501);
$server->set([
'heartbeat_check_interval' => 1,
'heartbeat_idle_time' => 10
]);

$server->on('open', function (swoole_websocket_server $server, $request) {
echo "server: handshake success with fd{$request->fd}\n";
});

$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "this is server");
});

$server->on('close', function ($ser, $fd) {
echo "client {$fd} closed\n";
});

$server->start();

20 changes: 20 additions & 0 deletions log/sw_server.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[2018-10-08 18:17:28 @2971.0] TRACE hb timer start, time: 30 live time:60
[2018-10-08 18:17:28 #2971.1] TRACE check fd=5
[2018-10-08 18:17:29 *2980.1] DEBUG Context(:16): alloc stack: size=2097152, ptr=0x7f19edb2b010.
[2018-10-08 18:17:29 *2979.0] DEBUG Context(:16): alloc stack: size=2097152, ptr=0x7f19ed82a010.
[2018-10-08 18:17:29 *2979.0] DEBUG ~Context(:38): free stack: ptr=0x7f19ed82a010
[2018-10-08 18:17:29 *2980.1] DEBUG ~Context(:38): free stack: ptr=0x7f19edb2b010
[2018-10-08 18:17:58 #2971.1] TRACE check fd=5
[2018-10-08 18:18:28 #2971.1] TRACE check fd=5
[2018-10-08 18:18:58 #2971.1] TRACE check fd=5
[2018-10-08 18:19:28 #2971.1] TRACE check fd=5
[2018-10-08 18:19:58 #2971.1] TRACE check fd=5
[2018-10-08 18:20:28 #2971.1] TRACE check fd=5
[2018-10-08 18:20:58 #2971.1] TRACE check fd=5
[2018-10-08 18:21:09 @2984.0] TRACE hb timer start, time: 30 live time:60
[2018-10-08 18:21:09 #2984.1] TRACE check fd=5
[2018-10-08 18:21:10 *2992.0] DEBUG Context(:16): alloc stack: size=2097152, ptr=0x7f869222a010.
[2018-10-08 18:21:10 *2992.0] DEBUG ~Context(:38): free stack: ptr=0x7f869222a010
[2018-10-08 18:21:10 *2993.1] DEBUG Context(:16): alloc stack: size=2097152, ptr=0x7f869252b010.
[2018-10-08 18:21:10 *2993.1] DEBUG ~Context(:38): free stack: ptr=0x7f869252b010
[2018-10-08 18:21:39 #2984.1] TRACE check fd=5

0 comments on commit 8bb82a8

Please sign in to comment.