Build dynamic, interactive web applications using reusable PHP components with state management and SPA-like behavior — no JavaScript frameworks required.
|
🧩 Components
Reusable & Modular Build once, use everywhere |
🧠 State
Reactive Updates Auto-sync state changes |
⚡ Performance
Zero Full Reloads SPA-like experience |
🎯 Simple
Minimal Setup Works out of the box |
Get up and running in 30 seconds with a complete PhpSPA example
|
📦 Clone Template Pre-configured project structure |
⚡ Instant Setup Dependencies + server ready |
Step 1: Clone the Template
composer create-project phpspa/phpspa my-phpspa-app
cd my-phpspa-appStep 3: Start Development Server
composer start🎉 That's it! Your PhpSPA application is now running locally.
Open your browser and start building amazing components!
If you want to set up PhpSPA manually, maybe in an existing project, follow these steps:
composer require dconco/phpspaFirst you need to include the namespace at the beginning of your app.
<?php
use PhpSPA\App;
use PhpSPA\Component;
use function Component\useState;
require_once 'vendor/autoload.php';function HomePage() {
$counter = useState("count", 0);
return <<<HTML
<h1>Counter: {$counter}</h1>
<button onclick="setState('count', {$counter} + 1)">+</button>
<Component.Link to="/about" children="About" />
HTML;
}$app = new App(fn() => '<div id="app"></div>');
$app->attach((new Component('HomePage'))->route('/'));
$app->run();To enable the fastest HTML/CSS/JS compression, add this to your php.ini:
ffi.enable=true
extension=ffiThen add this line to your code:
use PhpSPA\Compression\Compressor;
$app->compression(Compressor::LEVEL_AGGRESSIVE, true)You’ll see X-PhpSPA-Compression-Engine: native in response headers when active.
|
🧱 Component Architecture
Clean, reusable PHP components |
🔄 Reactive State
Auto-updating UI with simple state management |
|
🌍 SPA Navigation
Smooth page transitions without reloads |
🪶 Lightweight
PhpSPA is dependency-free, which makes it extra fast |
|
🛡️ SEO Ready
Server-rendered for search engines |
⚙️ Framework Agnostic
Works with any PHP setup |
🔗 Complete Documentation — Full tutorials, examples and guides
👉 API References — Detailed API documentation for all PhpSPA features
📦 Packagist — Installation and versions
We welcome contributions from the community! Whether you want to add new hooks, fix bugs, or improve documentation, your help is appreciated.
👉 Read our Contributing Guide to get started