dconco/phpspa

A component-based library for building modern, reactive user interfaces in pure PHP. Inspired by React. ✨

Maintainers

Details

github.com/dconco/phpspa

Source

Issues

Fund package maintenance!
dconco
Buy Me A Coffee

Installs: 218

Dependents: 1

Suggesters: 0

Security: 0

Stars: 48

Watchers: 0

Forks: 8

Open Issues: 0

pkg:composer/dconco/phpspa

v2.0.3 2025-11-28 10:31 UTC

README

PhpSPA - Component-Based PHP Library

Component-Based PHP Library for Modern Web Applications

Build dynamic, interactive web applications using reusable PHP components with state management and SPA-like behavior — no JavaScript frameworks required.


License Documentation GitHub stars PHP Version Downloads PHP Tests


Key Features

🧩 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

🚀 Getting Started

🎯 Ready to Jump In? Start with our Template!

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-app

Step 3: Start Development Server

composer start

🎉 That's it! Your PhpSPA application is now running locally.

Open your browser and start building amazing components!

🚀 Quick Start

If you want to set up PhpSPA manually, maybe in an existing project, follow these steps:

Install

composer require dconco/phpspa

Namespace

First you need to include the namespace at the beginning of your app.

<?php

use PhpSPA\App;
use PhpSPA\Component;

require_once 'vendor/autoload.php';

Create Component

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;
}

Setup App

$app = new App(fn() => '<div id="app"></div>');

$app->attach((new Component('HomePage'))->route('/'));
$app->run();

⚡ Native Compression (C++ FFI)

To enable the fastest HTML/CSS/JS compression, add this to your php.ini:

ffi.enable=true
extension=ffi

Then 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.

🎨 What You Get

🧱 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

📚 Learn More

🔗 Complete Documentation — Full tutorials, examples and guides

👉 API References — Detailed API documentation for all PhpSPA features

📦 Packagist — Installation and versions

🤝 Contributing

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



✨ Crafted with Precision By

Dave Conco

Building modern web applications with the simplicity of PHP

GitHub Twitter Email Website

⭐ If you find PhpSPA useful, please give it a star!

MIT License