/swoole-examples

Examples on how to use the Swoole async PHP framework

Primary LanguagePHPMIT LicenseMIT

Swoole Example Projects

Examples on how to use the swoole async PHP framework

Examples Inside

  • serve-file: server a file using the correct mimetype
  • client: make an async call to an external domain and download the page
  • channel: share memory and data between coroutines
  • process: load an external program and run it multiple processes
  • router: use an off-the-rack router (nikic/fast-route) to route request methods and URIs
  • websocket: a chat example with websockets
  • slim: an example of how to use the Slim Framework
  • users: using Swoole with Laravel with the laravel-swoole/wiki/Z1.-Notices
  • event-source: an example of the EventSource long-lived connection

Installation

Take a look inside docker-compose.yml and uncomment the example you want to run.

  • composer install
  • docker-compose up

Installation for Laravel example

  • cd users
  • composer install
  • cp .env.example .env
  • Update DB_CONNECTION=sqlite and comment out any other DB_* lines
  • touch database/database.sqlite
  • php artisan key:generate
  • php artisan migrate
  • php artisan db:seed

Development

When modifying files, you need to restart the docker instance to see the changes. This is because the files are loaded into Swooles memory and therefore cannot be modified after the server is started. You may be familiar with this workflow if you developed anything using Node.js.