Home > PHP Framework > Swoole > What should I do if oppo cannot connect to swoole?

What should I do if oppo cannot connect to swoole?

藏色散人
Release: 2020-04-09 09:53:07
Original
2301 people have browsed it

What should I do if oppo cannot connect to swoole?

Unable to connectswooleWhat should I do? Websocket cannot connect to the https server enabled by swoole?

The problem of connecting https in swoole

Some time ago, a friend consulted a PHP blogger about the problem of websocket connecting to HTTPS. The online information was very confusing, so the blogger also tried it himself. Some questions and technical summaries are shared with you.

The server is developed using the PHP extended Swoole framework, and the client is developed using websocket in JS.

HTTPS solution is as follows:

1. Remember to select support for openssl when compiling and installing swoole.

cd swoole_srcphpize ./configure --enable-openssl make && make install
2.如果遇到报错configure: error: Cannot find php-config. Please use --with-php-config=PATH
Copy after login

Solution: Manually add the php-config path

./configure --with-php-config=/usr/local/php/bin/php-config --enable-openssl
Copy after login

3. Finally add the certificate information to the swoole code:

//初始化类的时候,加上openssl参数
$serv = new swoole_websocket_server(":", 8080, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
//配置证书文件位置
$key_dir = "YOUR_KEY_DIR";
$serv->set(array( 'work_num'=>1, 'ssl_cert_file'=>$key_dir.'/file.crt','ssl_key_file'=>$key_dir.'file.key'));
Copy after login

4. Client connection:

var wsl = "wss://domain/path";//证书的域名 ws = new WebSocket(wsl);
Copy after login

Be sure to change ws to wss when the client connects.

The above is the detailed content of What should I do if oppo cannot connect to swoole?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template