skoro/slim-swoole-project

Slim Framework + Swoole project boilerplate

dev-master 2022-11-28 18:32 UTC

This package is auto-updated.

Last update: 2024-04-25 00:59:47 UTC


README

A project boilerplate of Slim Framework and Swoole an event-based asynchronous PHP extension.

Requirements

Getting Started

Start your new project with composer:

$ composer create-project skoro/slim-swoole-project <project-path>

Getting started with Docker

Download or clone this project then cd into the project directory and build a container:

docker-compose build --no-cache

Install dependencies and run the server:

docker-compose up -d
docker-compose exec php composer install
docker-compose exec php composer run server

Configuring

The default settings are good enough but if you need to customize them you have to start with copying stock settings:

$ cp .env.example .env

Starting the server

Then you can start the http server by running this command:

$ composer run server

It will listen to localhost and 9501 port if you left SERVER_ADDR and SERVER_PORT environment variables by default.

When you need to stop or restart the server by an external command like kill you also can use a pid file which is located in var/server.pid directory.

Debug

Please keep in mind, changing your project source code won't be applied automatically, you need to restart the server manually. To make life easier, you could enable DEBUG=true mode in your .env and the server will restart automatically depending on the project source code changes but this feature requires inotify extension to be installed. Instead of editing your .env you could start the server like this:

$ composer run server-debug

You should also pay attention xdebug is not compatible with Swoole (https://openswoole.com/docs/get-started/common-install-errors#trying-to-use-xdebug-and-swoole).

Dependency Injection

This project uses PHP-DI container implementation. The container itself and its dependencies are configured in config/container.php file. Keep in mind, you can use any psr-11 compatible container, so it's up to you which container to use.