β‘ 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.
π¦ 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