如何在cPanel中与laravel网页一起运行websocket? [英] How to run websocket alongside laravel webpage in cPanel?

查看:72
本文介绍了如何在cPanel中与laravel网页一起运行websocket?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有websocket的Laravel项目.我使用cPanel在服务器上克隆了该项目.现在,我可以通过类似 https://app.example.com 的子域来访问正在运行的Laravel项目.但是由于超时,我无法将Websocket与该域名一起使用.

I have the Laravel project with websocket. I cloned the project on server with cPanel. Now I can access the running Laravel project through a sub domain like https://app.example.com. But I can not able to use the websocket with that domain name, because time out.

我使用的websocket是wss.我使用以下命令运行websocket:php artisan websocketsecure:init.该命令已成功运行,但无法使用.我尝试了以下地址wss://app.example.com:8090

The websocket which I using is wss. I used the following command to run the websocket : php artisan websocketsecure:init. The command is running successfully, but I can't able to use. I tried the following address wss://app.example.com:8090

如何在Laravel项目中访问安全的Websocket?

How can I access the secure websocket in the Laravel project?

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory;
use React\Socket\SecureServer;
use React\Socket\Server;
use App\Http\Controllers\WebSocketController;

class WebSocketSecureServer extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'websocketsecure:init';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $loop   = Factory::create();
        $webSock = new SecureServer(
            new Server('0.0.0.0:8090', $loop),
            $loop,
            array(
                'local_cert'        => '/apache/conf/ssl.crt/server.crt', // path to your cert
                'local_pk'          => '/apache/conf/ssl.key/server.key', // path to your server private key
                'allow_self_signed' => TRUE, // Allow self signed certs (should be false in production)
                'verify_peer' => FALSE
            )
        );
        // Ratchet magic
        $webServer = new IoServer(
            new HttpServer(
                new WsServer(
                    new WebSocketController()
                )
            ),
            $webSock
        );
        $loop->run();
    }
}

推荐答案

运行websocket基本上有两个要求:

Well to run websockets you have 2 requirements basically:

  • 能够运行该服务(检查,您显然可以这样做)
  • 访问服务器(您的服务器可能没有开放给外部的8090端口)

最后一部分可能是您的问题所在.

The last part is probably where your problem lies.

这篇关于如何在cPanel中与laravel网页一起运行websocket?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆