Home > PHP Framework > Swoole > body text

Can swoole configure certificates?

(*-*)浩
Release: 2019-12-12 11:52:00
Original
2813 people have browsed it

Can swoole configure certificates?

After successfully using swoole_websocket_server to open the websocket service, I encountered a problem. Most of the web is https, especially when it comes to high security and the design of Internet finance and digital currency. At all times, https is required. At this time, the ws:// connection will be prohibited due to security issues.

Install swoole's openssl support. (Recommended Learning: SWOOLE Video Tutorial )

Re-compilation and installation of SWOOLE source code, plus --enable-openssl

%PHP_BIN%/phpize
cd swoole_src
./configure --enable-openssl
make && make install
Copy after login

## code ssl replaces ws

Server, compare the last code, make the following changes

//初始化类的时候,加上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

Client, change the connection to wss

var wsl = "wss://domain/path";
ws = new WebSocket(wsl);
Copy after login

The above is the detailed content of Can swoole configure certificates?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!