laravel-swoole
laravel-swoole copied to clipboard
Target class [swoole.websocket] does not exist.
Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)
- Please provide your PHP and Swoole version. (
php -v
andphp --ri swoole
) PHP Version | 7.3.11 Swoole Version | 4.4.17 - Please provide your Laravel/Lumen version. Laravel Version | 7.5.2
- Which release version of this package are you using? ^2.6
- What did you do? If possible, provide a recipe for reproducing the error
use SwooleTW\Http\Websocket\Facades\Websocket;
Websocket::toUserId(1)->emit('message','test');
- What did you expect to see? I expected the websocket to emit the data to my client
But it is normal in websocket handler
- What did you see instead? Illuminate\Contracts\Container\BindingResolutionException Target class [swoole.websocket] does not exist.
Added Package Service Providers:
app.php SwooleTW\Http\LaravelServiceProvider::class
But it can't run please for help @albertcht
pecl compile without websocket support, reinstall swoole with support websockets
pecl compile without websocket support, reinstall swoole with support websockets
Source code install But it can't
Same issue here.
pecl recompile / reinstall with all options YES, but still not working.
running the code below, works fine, but not with swooletw, why?
<?php
use Swoole\WebSocket\Server;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
$server = new Server("0.0.0.0", 9502);
$server->on("start", function (Server $server) {
echo "Swoole WebSocket Server is started at http://127.0.0.1:9502\n";
});
$server->on('open', function(Server $server, Swoole\Http\Request $request) {
echo "connection open: {$request->fd}\n";
$server->tick(1000, function() use ($server, $request) {
$server->push($request->fd, json_encode(["hello", time()]));
});
});
$server->on('message', function(Server $server, Frame $frame) {
echo "received message: {$frame->data}\n";
$server->push($frame->fd, json_encode(["hello", time()]));
});
$server->on('close', function(Server $server, int $fd) {
echo "connection close: {$fd}\n";
});
$server->start();
How did you run it @adrianowead ?
How did you run it @adrianowead ?
The code above are available on https://www.swoole.co.uk/docs/modules/swoole-websocket-server
To run, justo save file and execute on bash:
php websocket.php
I also encountered the same problem.
The operating environment is as follows: PHP Version | 7.2.34 Swoole Version | 4.4.17 Laravel Version | 6.20.27 This package Version | "^2.8"
Error message:
Illuminate\Contracts\Container\BindingResolutionException : Target class [swoole.websocket] does not exist.
at /usr/local/var/www/laravel_im/vendor/laravel/framework/src/Illuminate/Container/Container.php:805 801| 802| try { 803| $reflector = new ReflectionClass($concrete); 804| } catch (ReflectionException $e) {
805| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 806| } 807| 808| // If the type is not instantiable, the developer is attempting to resolve 809| // an abstract type such as an Interface or Abstract Class and there is
Exception trace:
1 ReflectionException::("Class swoole.websocket does not exist") /usr/local/var/www/laravel_im/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
2 ReflectionClass::__construct("swoole.websocket") /usr/local/var/www/laravel_im/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
@nifengfanpan Is this problem finally solved?
@nifengfanpan 这个问题终于解决了?
大哥你解决了嘛,我PHP8.1 SWOOLE4.8.4报了一样的错误
你看下是不是在启动了swoole的环境下运行的,我使用的是php7.3 + swoole4.+版本 原因是我在web环境调用的接口造成失败,实际上是需要在启动了swoole的环境使用,比如我安装的虚拟机,虚拟机里安装swoole,在虚拟机里操作就没有问题了
------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月20日(星期一) 下午2:45 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [swooletw/laravel-swoole] Target class [swoole.websocket] does not exist. (#415)
@nifengfanpan 这个问题终于解决了?
大哥你解决了嘛,我PHP8.1 SWOOLE4.8.4报了一样的错误
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
你看下是不是在启动了swoole的环境下运行的,我用的是php7.3+swoole4.+版本原因是我在web环境调用的接口导致失败,实际上是需要在启动了swoole的环境使用,比如我安装的虚拟机,虚拟机里安装swoole,在虚拟机里操作就没有问题了 … ------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月20日(星期一) 下午2:45 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [swooletw/laravel-swoole] Target class [swoole.websocket] does not exist. (#415) @nifengfanpan 这个问题终于解决了? 大哥你解决了嘛,我PHP8.1 SWOOLE4.8.4报了一样的错误 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
我也是在虚拟机上运行的,肯定是在swoole的环境下,因为我注释掉websocket路由可以正常启动
嗯嗯,我的意思是即使调用接口也要在虚拟机环境下,如果这样也不行的话那你和我的问题就不一样了,可能是PHP8的原因,可能是其他原因,或者你尝试下降到7.3版本运行试试
------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月20日(星期一) 下午3:03 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [swooletw/laravel-swoole] Target class [swoole.websocket] does not exist. (#415)
你看下是不是在启动了swoole的环境下运行的,我用的是php7.3+swoole4.+版本原因是我在web环境调用的接口导致失败,实际上是需要在启动了swoole的环境使用,比如我安装的虚拟机,虚拟机里安装swoole,在虚拟机里操作就没有问题了 … ------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月20日(星期一) 下午2:45 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [swooletw/laravel-swoole] Target class [swoole.websocket] does not exist. (#415) @nifengfanpan 这个问题终于解决了? 大哥你解决了嘛,我PHP8.1 SWOOLE4.8.4报了一样的错误 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
我也是在虚拟机上运行的,肯定是在swoole的环境下,因为我注释掉websocket路由可以正常启动
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
The same issue. I can't resolve.
Someone solved this problem? PHP Version | 8.1.27 Swoole Version | 5.1.1 Laravel Version | 10.46.0
@Rakashikov, If your setup includes PHP-FPM, it's important to note that it will not function alongside Swoole. To succinctly put it, you must employ the Swoole HTTP server to enable the use of the [swoole.websocket] class.
PHP-FPM and Swoole are both process managers designed with distinct functionalities in mind and are not intended to work in conjunction. Specifically, the Websocket server is initialized solely through the swoole:http start command, making it accessible only to HTTP requests managed by the Swoole server. This setup enables Swoole to handle all HTTP requests, leveraging its benefits, such as keeping the application loaded in memory for quicker responses. Consequently, PHP-FPM becomes unnecessary in this context, allowing swoole:http to serve as the primary process in the PHP container.
Upon examining the package code, it's evident that Websocket initialization occurs within Concerns\InteractsWithWebsocket, a component exclusively utilized by Server\Manager. This particular instance is generated solely through Commands/HttpServerCommand. Attempting to instantiate it within a PHP-FPM environment results in an exception, underscoring the incompatibility between PHP-FPM and Swoole in this scenario.