Home > Article > PHP Framework > 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
Solution: Manually add the php-config path
./configure --with-php-config=/usr/local/php/bin/php-config --enable-openssl
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'));
4. Client connection:
var wsl = "wss://domain/path";//证书的域名 ws = new WebSocket(wsl);
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!