crazy-goat / micro-app
A lightweight micro PHP application framework
v1.0.2
2025-08-13 21:42 UTC
Requires
- php: ^8.1
- ext-pcntl: *
- ext-posix: *
- nikic/fast-route: ^1.3
- symfony/console: ^7.3
- workerman/workerman: ^5.1
Requires (Dev)
- php-cs-fixer/shim: ^3.85
- rector/rector: ^2.1
README
MicroApp is a minimalist PHP micro-backend framework built to run on top of the fast Workerman HTTP server. It enables you to quickly create lightweight micro-backends using Symfony commands and attribute-based routing.
Features
- Minimal setup, rapid development for micro-backends
- Runs on Workerman for high-performance HTTP serving
- Attribute-based routes using PHP 8+ attributes
- Symfony Console integration for easy command management
- Configurable port, interface, and worker count
Getting Started
Dependencies
- PHP 8.1+
- Workerman
- Symfony Console
- FastRoute
Installation
Install MicroApp via Composer:
composer require crazy-goat/micro-app
Creating a Micro-Backend
- Create a Symfony Application using
MicroApp
:
<?php # myapp.php require __DIR__.'/../vendor/autoload.php'; use CrazyGoat\MicroApp\Attributes\Route; use CrazyGoat\MicroApp\MicroApp; use Workerman\Protocols\Http\Request; use Workerman\Protocols\Http\Response; class HelloWorldController { #[Route] public function handle(Request $request): Response { return new Response(body:'Hello World'); } } (new MicroApp()) ->withController(new HelloWorldController()) ->getApplication() ->run();
- Your controller must have at least one function with the
#[Route]
attribute. - Each route function must accept a
Request
and return aResponse
.
- Run your application:
Example:
php myapp.php server start --listen=127.0.0.1 --port=8081
Configuration Options
Option | Description | Default |
---|---|---|
--port |
Port to listen on | 8080 |
--listen |
Interface/address to bind | 0.0.0.0 |
--workers |
Number of PHP worker processes | 4 |
--reuse_port |
Use SO_REUSEPORT if available | false |
--dev |
Reload server every request. Use for development | false |
--max-reques |
Reload server N request. Use this if you have memory leaks. | null |
--reload-on-exception |
If exception appears in code, reload worker. | false |
Server commands
server start
- Start the serverserver stop
- Stop the serverserver restart
- Restart the serverserver reload
- Reload the serverserver status
- Show the server statusserver connections
- Show the server connections
License
MIT