Home  >  Article  >  PHP Framework  >  Can swoole configure certificates?

Can swoole configure certificates?

(*-*)浩
(*-*)浩Original
2019-12-12 11:52:002805browse

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

## 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'
                )
            );

Client, change the connection to wss

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

The above is the detailed content of Can swoole configure certificates?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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