Closed cq-z closed 8 years ago
请贴出完整的运行时设置参数。
[server]
; port
listen = 12312
address = "0.0.0.0"
;server port
manager_address = 127.0.0.1
manager_listen = "12333"
[setting]
;设置启动的worker进程数量。swoole采用固定worker进程的模式
worker_num = 1
;配置task进程的数量,配置此参数后将会启用task功能
task_worker_num = 1
;1平均分配,2按FD取摸固定分配,3抢占式分配,默认为取摸(dispatch=2)
dispatch_mode = 2
;守护进程化
daemonize = 0
;最大连接
max_conn =250
;Listen队列长度
backlog = 128
;设置最大数据包尺寸
package_max_length = 12582912
;数据发送缓存区
buffer_output_size= 12582912
; 日记
log_file = SWOOLEBASEPATH'/../Apps/Cache/swoole.log'
;日记等级
log_level = 1
;心跳检查
;单位秒,Swoole会轮询所有TCP连接,将超过心跳时间的连接关闭掉
heartbeat_check_interval = 60
;TCP连接的最大闲置时间,单位s
heartbeat_idle_time = 1800
;CPU
;此参数表示worker进程在处理完n次请求后结束运行防止worker进程内存溢出
max_request=1
;reactor_num和writer_num默认设置为CPU核数。通过此参数来调节poll线程的数量,以充分利用多核
;reactor_num=> 2,//reactor线程数
;writer_num=>2,Writer线程数
;open_cpu_affinity => 1 ,//启用CPU亲和设置
;cpu_affinity_ignore,网络中断会分布到多核,可以缓解网络中断的压力
;加密
;SSL证书
ssl_cert_file = SWOOLEBASEPATH'/certs/domain.crt'
;SSL私钥
ssl_key_file = SWOOLEBASEPATH'/certs/domain.key'
open_http2_protocol = true
docker编译文件Dockerfile
FROM php:5.6-fpm
# Install env
ADD sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y \
git \
libgearman-dev \
libmemcached-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
libhiredis-dev \
libssl-dev \
libnghttp2-dev \
&& apt-get clean && apt-get autoclean \
&& rm -r /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install zip \
&& docker-php-ext-install gd \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mcrypt \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install opcache
COPY swoole-1.8.2.tgz /home/swoole.tgz
RUN cd /home && tar zxvf swoole.tgz && cd swoole-1.8.2 && /usr/local/bin/phpize && ./configure --enable-async-redis \
--enable-openssl --enable-http2 && make && make install \
&& echo "extension=swoole.so" > /usr/local/etc/php/conf.d/swoole.ini \
&& rm /home/swoole.tgz && rm -rf /home/swoole-1.8.2
请用 最新的github master分支代码测试一下。
最新版本,PHP代码没有变化报错:
[2016-03-16 21:03:18 @21.0] WARNING swPort_listen: need to configure [server->ssl_cert_file].
PHP Fatal error: swoole_server::__construct(): listen server port failed. in /data/www/aries-service/webSocket/service.php on line 31
Fatal error: swoole_server::__construct(): listen server port failed. in /data/www/aries-service/webSocket/service.php on line 31
换了一种写法,先监听其他端口然后配置。最后监听ssl 报错:
["open_eof_check"]=>
string(0) ""
["open_eof_split"]=>
bool(false)
["max_request"]=>
int(1)
["ssl_cert_file"]=>
string(50) "/data/www/aries-service/webSocket/certs/domain.crt"
["ssl_key_file"]=>
string(50) "/data/www/aries-service/webSocket/certs/domain.key"
["open_http2_protocol"]=>
bool(true)
}
[2016-03-16 21:21:25 @185.0] WARNING swPort_listen: need to configure [server->ssl_cert_file].
vagrant@ubuntu-14:/data/docker-lnmp$
已更新代码,请git pull后,执行make clean && make -j install ,然后再进行测试。
我用的是自己生成的SSL证书这个应该没关系把。WSS是正常的https现在的报错:
[2016-03-17 13:02:48 @35.0] WARNING swSSL_server_config: SSL_CTX_set_cipher_list("EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH") failed
[2016-03-17 13:02:48 @35.0] WARNING swPort_set_option: swSSL_server_config() error.
2016-03-17 14:02:48:主进程Pid=35|管理的pid=40
2016-03-17 14:02:48:Server: start.Swoole version is [1.8.3-rc1]
2016-03-17 14:03:01:client 1 closed
[2016-03-17 13:03:21 #35.0] WARNING swSSL_accept: bad SSL client[10.211.55.1:57865].
[2016-03-17 13:03:21 #35.0] WARNING swSSL_recv: SSL_read(15, 4294967288) failed, errno=1.
[2016-03-17 13:03:21 #35.0] WARNING swSSL_recv: SSL_read(15, 4294967288) failed, errno=1.
[2016-03-17 13:03:21 #35.0] WARNING swSSL_recv: SSL_read(15, 4294967288) failed, errno=1.
[2016-03-17 13:03:21 #35.0] WARNING swSSL_recv: SSL_read(15, 4294967288) failed, errno=1.
[2016-03-17 13:03:21 #35.0] WARNING swSSL_recv: SSL_read(15, 4294967288) failed, errno=1.
open_http2_protocol = false 关闭http2,HTTPS就能正常访问了。。。但是http就不行。
[2016-03-17 13:14:37 @92.0] WARNING swSSL_server_config: SSL_CTX_set_cipher_list("EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH") failed
[2016-03-17 13:14:37 @92.0] WARNING swPort_set_option: swSSL_server_config() error.
2016-03-17 14:14:37:主进程Pid=92|管理的pid=97
2016-03-17 14:14:37:Server: start.Swoole version is [1.8.3-rc1]
2016-03-17 14:14:40:client 1 closed
http访问报错:
[2016-03-17 13:15:11 #92.0] WARNING swSSL_accept: bad SSL client[10.211.55.1:57985].
[2016-03-17 13:15:11 #92.0] WARNING swSSL_accept: bad SSL client[10.211.55.1:57986].
opssl版本
root@eb4296a9ce61:/data# openssl version -a
OpenSSL 1.0.1k 8 Jan 2015
built on: Mon Feb 29 17:54:55 2016
platform: debian-amd64
options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx)
compiler: -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/lib/ssl"
open_http2_protocol无论是否开启,http,https都无法访问。log如下
2016-03-17 16:20:26:[open_http2_protocol = false]主进程Pid=69|管理的pid=74
2016-03-17 16:20:26:Server: start.Swoole version is [1.8.3-rc1]
2016-03-17 16:20:31:[https]client 1 closed
2016-03-17 16:21:36:[open_http2_protocol = true]主进程Pid=85|管理的pid=91
2016-03-17 16:21:36:Server: start.Swoole version is [1.8.3-rc1]
[2016-03-17 15:21:49 #85.0][http] WARNING swSSL_accept: bad SSL client[10.211.55.1:59399].
2016-03-17 16:22:59:[https]client 3 closed
同一个监听的WSS就是OK的 Request URL:wss://127.0.0.1:12312 Request Method:GET Status Code:101 Switching Protocols
已经解决谢谢大神帮忙。 注意:swoole_websocket_server的onRequest回调,websocket服务器也可以同时作为http服务器 不能使用http2
@cq-z 你的docker下的swoole压测情况怎么样?
功能还没开发完没做压测和优化。docker目前只是在开发环境上用。
环境是: PHP 5.6.18 (cli) (built: Feb 17 2016 01:33:33) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies docker镜像 php 5.6-fpm 602f79ac154a 宿主机器:Ubuntu 14.04.4 LTS \n \l 通过sudo apt-get install libnghttp2-dev安装nghttp2库 编译的时候有提示: `/home/swoole-1.8.2/swoole_http_v2_server.c: In function 'http2_parse_header': /home/swoole-1.8.2/swoole_http_v2_server.c:294:13: warning: format '%zd' expects argument of type 'signed size_t', but argument 5 has type 'int' [-Wformat=] swoole_php_error(E_WARNING, "nghttp2_hd_inflate_init() failed, Error: %s[%zd].", nghttp2_strerror(ret), ret); ^ In file included from /usr/local/include/php/Zend/zend.h:252:0, from /usr/local/include/php/main/php.h:35, from /home/swoole-1.8.2/php_swoole.h:22, from /home/swoole-1.8.2/swoole_http_v2_server.c:17: /home/swoole-1.8.2/swoole_http_v2_server.c: In function 'swoole_http2_do_response': /usr/local/include/php/Zend/zend_alloc.h:72:26: warning: 'date_str' may be used uninitialized in this function [-Wmaybe-uninitialized]
define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
/home/swoole-1.8.2/swoole_http_v2_server.c:69:11: note: 'date_str' was declared here char *date_str; ^
PHP代码
$server = new swoole_websocket_server( $serverConf['address'], $serverConf['listen'],SWOOLE_PROCESS,SWOOLE_SOCK_TCP | SWOOLE_SSL );`
配置
;加密 ;SSL证书 ssl_cert_file = SWOOLEBASEPATH'/certs/domain.crt' ;SSL私钥 ssl_key_file = SWOOLEBASEPATH'/certs/domain.key' open_http2_protocol = true