⚑ BareMetalPHP

Lightning-fast PHP framework powered by Go. Persistent workers, hot reload, and multi-pool concurrencyβ€”without extensions.

πŸš€

Go-Powered Runtime

Built-in Go application server with persistent PHP workers. No cold starts, no PHP-FPM.

πŸ”₯

Hot Reload

Automatic file watching and reload. Code changes reflect instantly in development.

⚑

Multi-Pool Concurrency

Separate fast and slow worker pools for optimal request handling.

πŸ“¦

Zero Extensions

Pure PHP and Go. No Swoole, no Octane dependenciesβ€”just portable performance.

🎯 Introduction

BareMetalPHP is a modern, lightweight PHP framework built for speed, simplicity, and developer happiness. It's powered by an optional Go application server that enables persistent PHP workers, hot reload, multi-pool concurrency, and static file acceleration.

Core Value Proposition The Go App Server delivers performance similar to Laravel Octane or Swoole, but simpler, more portable, and without PHP extensions.

πŸ“¦ Installation

Create a New Project

composer create-project baremetalphp/baremetalphp myapp
cd myapp

Start the Development Server

php mini serve

Your application is now running at http://localhost:8000

πŸš€ Go Application Server

The BareMetalPHP Go Application Server is a high-performance, production-ready runtime that replaces traditional PHP-FPM with persistent PHP workers.

✨ Key Features

  • Persistent PHP workers (no cold starts)
  • Fast/slow worker classification for optimal load balancing
  • Automatic hot reload via fsnotify
  • Static asset acceleration
  • JSON bridge protocol between Go and PHP

Installation

Install the Go server scaffold:

php mini go:install
go mod tidy

Start the Go Runtime

php mini go:serve

Configuration

Edit config/appserver.php:

return [
    'enabled'      => env('APPSERVER_ENABLED', false),
    'fast_workers' => env('APPSERVER_FAST_WORKERS', 4),
    'slow_workers' => env('APPSERVER_SLOW_WORKERS', 2),
    'hot_reload'   => env('APPSERVER_HOT_RELOAD', true),
];

Generated JSON Config

{
  "FastWorkers": 4,
  "SlowWorkers": 2,
  "HotReload": true,
  "Static": [
    {"Prefix": "/css/", "Dir": "public/css"},
    {"Prefix": "/js/", "Dir": "public/js"},
    {"Prefix": "/images/", "Dir": "public/images"}
  ]
}

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     Request     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Browser/CLI  β”‚ ───────────────▢ β”‚ BareMetalPHP Go Server β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚ β€’ Static files          β”‚
                                 β”‚ β€’ Hot reload            β”‚
                                 β”‚ β€’ Worker scheduling     β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚ Dispatch
                                               β–Ό
                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                 β”‚ Persistent PHP Workers  β”‚
                                 β”‚ β€’ bootstrap_app.php     β”‚
                                 β”‚ β€’ bridge.php            β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β–Ό
                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                 β”‚  BareMetalPHP Framework  β”‚
                                 β”‚ β€’ Router                 β”‚
                                 β”‚ β€’ Kernel                 β”‚
                                 β”‚ β€’ DI Container           β”‚
                                 β”‚ β€’ Controllers/Views      β”‚
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧠 PHP Kernel

The Kernel is the heart of BareMetalPHP. It receives requests from the Go server, resolves routes, executes controllers, and returns responses.

In persistent mode, the kernel bootstraps once and handles multiple requests, dramatically improving performance over traditional request-per-process models.

πŸ›£ Routing

Define your application routes with a clean, expressive syntax:

// Simple closure route
$router->get('/', function () {
    return "Hello world";
});

// Route with parameters
$router->get('/user/{id}', 'UserController@show');

// Named routes
$router->get('/posts', 'PostController@index')->name('posts.index');

// Route groups
$router->group(['prefix' => 'api'], function ($router) {
    $router->get('/users', 'UserController@index');
    $router->post('/users', 'UserController@store');
});

πŸ“ Controllers

Controllers handle your application logic with automatic dependency injection:

namespace App\Controllers;

class UserController
{
    public function show(\App\Models\User $user)
    {
        return view('user.show', ['user' => $user]);
    }

    public function store(Request $request)
    {
        $user = User::create($request->all());
        
        return redirect()->route('users.show', $user->id);
    }
}

Create a Controller

php mini make:controller UserController

🧩 Dependency Injection

BareMetalPHP includes a powerful DI container for managing dependencies:

// Bind an interface to a concrete implementation
$app->bind(LoggerInterface::class, FileLogger::class);

// Bind a singleton
$app->singleton(Database::class, function ($app) {
    return new Database($app['config']['database']);
});

// Resolve from container
$logger = $app->make(LoggerInterface::class);

Controllers automatically resolve dependencies from the container, making testing and maintainability simple.

🎨 Views & Templates

Render views with a simple, intuitive API:

// Return a view
return view('welcome', ['name' => 'Elliot']);

// View with data
return view('posts.index', [
    'posts' => Post::all(),
    'title' => 'All Posts'
]);

Template Example

<!-- resources/views/welcome.php -->
<!DOCTYPE html>
<html>
<head>
    <title>Welcome</title>
</head>
<body>
    <h1>Hello, <?= htmlspecialchars($name) ?>!</h1>
</body>
</html>

πŸ—„ Database & Migrations

Manage your database schema with version-controlled migrations:

Create a Migration

php mini make:migration create_users_table

Run Migrations

php mini migrate

Rollback Migrations

php mini migrate:rollback

Migration Example

use Database\Migration;

return new class extends Migration
{
    public function up()
    {
        $this->schema->create('users', function ($table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamps();
        });
    }

    public function down()
    {
        $this->schema->drop('users');
    }
};

πŸ§ͺ Testing

BareMetalPHP includes PHPUnit for testing out of the box:

vendor/bin/phpunit

Test Example

namespace Tests\Feature;

use Tests\TestCase;

class ExampleTest extends TestCase
{
    public function test_homepage()
    {
        $response = $this->get('/');
        
        $response->assertStatus(200);
        $response->assertSee('Welcome');
    }
}

πŸ”§ CLI Commands

The mini CLI provides useful commands for development:

# Start development server
php mini serve

# Go server commands
php mini go:install
php mini go:serve

# Generate code
php mini make:controller UserController
php mini make:migration create_posts_table

# Database
php mini migrate
php mini migrate:rollback

# Run tests
php mini test

πŸ— Project Structure

BareMetalPHP follows a clean, intuitive directory structure:

myapp/
β”œβ”€β”€ app/                    # Application code
β”‚   β”œβ”€β”€ Controllers/        # HTTP controllers
β”‚   β”œβ”€β”€ Models/            # Data models
β”‚   └── Middleware/        # HTTP middleware
β”œβ”€β”€ config/                # Configuration files
β”‚   β”œβ”€β”€ app.php
β”‚   β”œβ”€β”€ database.php
β”‚   └── appserver.php      # Go server config
β”œβ”€β”€ database/              # Database files
β”‚   └── migrations/        # Database migrations
β”œβ”€β”€ public/                # Web root
β”‚   β”œβ”€β”€ index.php         # Entry point
β”‚   β”œβ”€β”€ css/
β”‚   β”œβ”€β”€ js/
β”‚   └── images/
β”œβ”€β”€ routes/                # Route definitions
β”‚   └── web.php
β”œβ”€β”€ server/                # Go runtime source
β”‚   └── main.go
β”œβ”€β”€ php/                   # PHP worker files
β”‚   β”œβ”€β”€ bootstrap_app.php
β”‚   └── bridge.php
β”œβ”€β”€ resources/             # Views and assets
β”‚   └── views/
β”œβ”€β”€ tests/                 # Test suite
└── vendor/                # Composer dependencies