Swoole Symfony Integration Guide

The community is asking for how to use Swoole with Symfony and how to integrate a Symfony project with PHP Swoole.

Swoole libraries for Symfony

Symfony Swoole Bundle:

https://github.com/k911/swoole-bundle

Features:

  • Built-in API Server
  • Swoole Bundle API Server allows to manage Swoole HTTP Server in real time.
  • Improved static files serving
  • Hot Module Reload (HMR) - for development
  • Symfony Messenger integration

It is a solution to integrate Symfony with Swoole to speed up your applications.

  1. Installation:
composer create-project symfony/skeleton project
cd ./project
composer require k911/swoole-bundle
  1. Update config file config/bundles.php:
<?php
return [
    // ...other bundles
    K911\Swoole\Bridge\Symfony\Bundle\SwooleBundle::class => ['all' => true],
];
  1. Start Swoole HTTP server
bin/console swoole:server:run
Symfony Swoole Bridge Bundle:

https://github.com/insidestyles/swoole-bridge-bundle

  1. Installation:
composer require insidestyles/swoole-bridge-bundle

  1. Update config.yml
swoole_bridge:
    server:
        port: "%web_server_port%"      #The port the socket server will listen on
        host: "%web_server_host%"
  1. Update AppKernel
<?php
    new Insidestyles\SwooleBridgeBundle\SwooleBridgeBundle(),
  1. Start Swoole HTTP server
php bin/console swoole:bridge:server