insidestyles/swoole-bridge-bundle
Composer 安装命令:
composer require insidestyles/swoole-bridge-bundle
包简介
Swoole Bridge For Php Frameworks
README 文档
README
Symfony Swoole Bridge Bundle
Requirements
- PHP >= 7.1
- symfony/framework-bundle: "^5.0|^6.0"
- insidestyles/swoole-bridge: "^1.0"
- symfony/console: "^5.0|^6.0",
- "laminas/laminas-diactoros": "^2.0"
Installation
This package is installable and autoloadable via Composer
composer require insidestyles/swoole-bridge-bundle
Update config.yml
swoole_bridge: server: port: "%web_server_port%" #The port the socket server will listen on host: "%web_server_host%" configs: document_root: '/app/public' enable_static_handler: true http_compression: true http_compression_level: 1
Update bundles
Insidestyles\SwooleBridgeBundle\SwooleBridgeBundle::class => ['all' => true],
Usage
php bin/console swoole:bridge:server
Create custom handler
One of common problems while running long lived program in php is "MySQL server has gone away" (Long lived php daemon running using reactphp, websocket, swoole, ..etc..). In this case we can create a custom handler to handle this error. For example:
class CustomHandler implements SwooleBridgeInterface { /** * @var SwooleBridgeInterface */ private $swooleBridge; /** * @var RegistryInterface */ private $doctrineRegistry; /** * @var LoggerInterface */ private $logger; /** * Handler constructor. * @param SwooleBridgeInterface $swooleBridge * @param null|LoggerInterface $logger */ public function __construct( SwooleBridgeInterface $swooleBridge, RegistryInterface $doctrineRegistry, ?LoggerInterface $logger = null ) { $this->swooleBridge = $swooleBridge; $this->doctrineRegistry = $doctrineRegistry; $this->logger = $logger ?? new NullLogger(); } /** * @inheritdoc */ public function handle( SwooleRequest $swooleRequest, SwooleResponse $swooleResponse ): void { try { $this->swooleBridge->handle($swooleRequest, $swooleResponse); } catch (PDOException $e) { $this->logger->error($e->getMessage()); /** @var Connection $connection */ $connection = $this->doctrineRegistry->getConnection(); if (!$connection->ping()) { $connection->close(); $connection->connect(); } $em = $this->doctrineRegistry->getEntityManager(); if (!$em->isOpen()){ $this->doctrineRegistry->resetManager(); } } catch (\Throwable $e) { $this->logger->error($e->getMessage()); } } }
Override default handler using symfony service decorator:
#config/services.yaml services: swoole_bridge.custom_handler: class: App\CustomHandler decorates: swoole_bridge.handler arguments: - '@swoole_bridge.custom_handler.inner' - '@doctrine' - '@logger'
insidestyles/swoole-bridge-bundle 适用场景与选型建议
insidestyles/swoole-bridge-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 390 次下载、GitHub Stars 达 31, 最近一次更新时间为 2018 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 insidestyles/swoole-bridge-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 insidestyles/swoole-bridge-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 390
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-08