我想在php symfony项目中从服务器向浏览器发送通知。 在symfony中有一种简单的方法吗?
答案 0 :(得分:1)
过去我尝试使用Wrench库,它有一个Symfony包:
https://github.com/varspool/WebsocketBundle
这是Wrench库的包装器,它允许您创建websocket应用程序。
配置似乎很简单:
# app/config/config.yml
varspool_websocket:
servers:
default: # Server name
listen: ws://192.168.1.103:8000 # default: ws://localhost:8000
# Applications this server will allow
applications:
- echo
- multiplex
# Origin control
check_origin: true
allow_origin: # default: just localhost (not useful!)
- "example.com"
- "development.localdomain"
# Other defaults
max_clients: 30
max_connections_per_ip: 5
max_requests_per_minute: 50
然后将WS应用程序声明为服务。
<!-- Application\ChatBundle\Resources\config\services.xml -->
<service id="chat_service" class="Application\ChatBundle\Services\ChatService">
<tag name="varspool_websocket.application" key="chat" />
</service>
要安装它,请使用composer:
composer require wrench/wrench
composer require varspool/websocket-bundle
其余的安装文档写在存储库中!
我没有尝试过,但也许有你的解决方案:)