crazy-goat/micro-app

A lightweight micro PHP application framework

v1.0.2 2025-08-13 21:42 UTC

This package is auto-updated.

Last update: 2025-08-14 06:09:18 UTC


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

Installation

Install MicroApp via Composer:

composer require crazy-goat/micro-app

Creating a Micro-Backend

  1. 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 a Response.
  1. 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 server
  • server stop - Stop the server
  • server restart - Restart the server
  • server reload - Reload the server
  • server status - Show the server status
  • server connections - Show the server connections

License

MIT

Credits