A modern, high-performance PHP framework with OpenSwoole support
Clean, elegant, and built for speed
Features β’ Quick Start β’ Documentation β’ CLI Tools β’ Performance
HasPHP combines the elegance of Laravel with the performance of OpenSwoole, delivering a framework that's both developer-friendly and production-ready. Whether you're building APIs, web applications, or microservices, HasPHP provides the tools you need to ship fast and scale efficiently.
// Clean, expressive routing
Router::get('/users/{id}', 'UserController@show');
// Powerful ORM
$users = User::where('active', 1)->with('posts')->get();
// Built-in API documentation
// Swagger UI automatically generated at /api/docs- OpenSwoole Integration: 10-50x faster than traditional PHP-FPM
- Coroutine Support: Non-blocking I/O for maximum concurrency
- Multi-Worker Architecture: Parallel request processing
- Memory Persistence: Objects stay in memory between requests
- Artisan CLI: Laravel-inspired command-line interface
- Code Generation: Controllers, models, and migrations
- Auto Migrations: Database schema versioning made easy
- Hot Reload: Development server with automatic restarts
- Component-based SPA: React-like frontend architecture
- RESTful APIs: Built-in API development tools
- Auto Documentation: Swagger/OpenAPI integration
- Dependency Injection: Clean, testable code structure
- Docker Support: Container-ready deployment
- Process Management: Daemon mode with PID management
- Error Handling: Comprehensive exception handling
- Logging: Structured logging with multiple drivers
| Component | Minimum | Recommended |
|---|---|---|
| PHP | 8.0+ | 8.4+ |
| Composer | 2.0+ | Latest |
| OpenSwoole | Optional | 22.0+ |
| Database | Any | MySQL 8.0+ |
- Memory: 512MB+ (2GB+ recommended)
- Disk: 100MB+ free space
- OS: Linux, macOS, Windows (WSL2)
# Clone repository
git clone https://github.com/your-org/hasphp.git
cd hasphp
# Install dependencies
composer install
# Set up environment
cp .env.example .env# Create SQLite database (default)
mkdir -p database
touch database/database.sqlite
# Or configure MySQL/PostgreSQL in .env
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_DATABASE=hasphp
# DB_USERNAME=root
# DB_PASSWORD=# Auto-detect best server (OpenSwoole or PHP built-in)
php artisan serve
# Or specify options
php artisan serve --port=8080 --host=0.0.0.0- π Homepage: http://localhost:8080
- π§ͺ API Demo: http://localhost:8080/demo
- π API Docs: http://localhost:8080/api/docs
- β‘ SPA Demo: http://localhost:8080/spa
HasPHP includes a powerful command-line interface inspired by Laravel's Artisan:
# Generate controllers
php artisan make:controller UserController
php artisan make:controller Api/PostController --api
php artisan make:controller ProductController --resource
# Generate models with relationships
php artisan make:model User --migration
php artisan make:model Post --migration --controller --api
# Generate database migrations
php artisan make:migration create_users_table --create=users
php artisan make:migration add_email_to_users --table=users# Run migrations
php artisan migrate
# Check migration status
php artisan migrate:status
# Rollback migrations
php artisan migrate:rollback
php artisan migrate:rollback --step=3
# Preview queries (dry run)
php artisan migrate --pretend# Development server
php artisan serve # Auto-detect best server
php artisan serve --port=9000 # Custom port
php artisan serve --openswoole # Force OpenSwoole
php artisan serve --fallback # Force PHP built-in
# Production server
php artisan server:start # Start production server
php artisan server:start --daemon # Background daemon mode
php artisan server:stop # Stop all servers
php artisan server:status # Show server status# List all commands
php artisan list
# Get help for specific command
php artisan help make:controller
php artisan migrate --helphasphp/
βββ app/
β βββ Controllers/ # HTTP controllers
β βββ Models/ # Eloquent models
β βββ Core/ # Framework core
β β βββ CLI/ # Command-line interface
β β βββ DB/ # Database abstraction
β β βββ Internal/ # Internal framework classes
βββ database/
β βββ migrations/ # Database migrations
βββ routes/
β βββ web.php # Web routes
β βββ api.php # API routes
βββ views/
β βββ components/ # Reusable components
β βββ layouts/ # Layout templates
βββ public/ # Public assets
βββ storage/ # Logs and cache
βββ artisan # CLI entry point
βββ composer.json # Dependencies
- Router matches incoming requests
- Middleware processes requests (CORS, auth, etc.)
- Controllers handle business logic
- Models interact with database
- Views render responses
- Response sent back to client
// Fluent query builder
$users = DB::table('users')
->where('active', 1)
->orderBy('created_at', 'desc')
->limit(10)
->get();
// Raw queries with bindings
$users = DB::query('SELECT * FROM users WHERE active = ?', [1]);// Model definition
class User extends Model
{
protected string $table = 'users';
protected array $fillable = ['name', 'email'];
public function posts()
{
return $this->hasMany(Post::class);
}
}
// Usage
$user = User::create(['name' => 'John', 'email' => '[email protected]']);
$posts = User::with('posts')->where('active', 1)->get();// Create migration
php artisan make:migration create_users_table --create=users
// Migration file
class CreateUsersTable
{
public function up()
{
$sql = "CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)";
$this->db->query($sql);
}
}// routes/web.php
Router::get('/', 'HomeController@index');
Router::get('/users/{id}', 'UserController@show');
Router::post('/users', 'UserController@store');
// Route groups
Router::group(['prefix' => 'api'], function() {
Router::get('/posts', 'Api\\PostController@index');
Router::post('/posts', 'Api\\PostController@store');
});class UserController
{
public function index($request, $response)
{
$users = User::all();
$response->json([
'success' => true,
'data' => $users
]);
}
public function show($request, $response, $id)
{
$user = User::find($id);
if (!$user) {
return $response->status(404)->json([
'success' => false,
'message' => 'User not found'
]);
}
$response->json([
'success' => true,
'data' => $user
]);
}
}<!-- views/spa.twig -->
<div x-data="spaApp()" x-init="init()">
<!-- Navigation -->
<nav>
<a href="#" @click="navigateTo('home')">Home</a>
<a href="#" @click="navigateTo('posts')">Posts</a>
<a href="#" @click="navigateTo('users')">Users</a>
</nav>
<!-- Dynamic components -->
<div x-show="currentRoute === 'home'">
{% include 'components/home.twig' %}
</div>
<div x-show="currentRoute === 'posts'">
{% include 'components/posts.twig' %}
</div>
</div>// Built-in HasJS framework
const api = new HasAPI('/api');
// Fetch data with coroutines
async function loadUsers() {
try {
const users = await api.get('/users');
updateUI(users);
} catch (error) {
showError('Failed to load users');
}
}| Server Type | Requests/sec | Memory Usage | Response Time |
|---|---|---|---|
| OpenSwoole | 15,000-50,000 | ~50MB | 2-5ms |
| PHP-FPM | 1,000-3,000 | ~100MB | 20-50ms |
| Built-in Server | 500-1,000 | ~80MB | 50-100ms |
- Memory Persistence: Objects stay in memory between requests
- Connection Pooling: Database connections reused across requests
- Coroutine Support: Non-blocking I/O operations
- Static File Serving: Direct file serving without PHP overhead
# Start production server
php artisan server:start --daemon --port=8080 --workers=4
# With process manager (PM2, Supervisor)
pm2 start ecosystem.config.js
# Docker deployment
docker build -t hasphp-app .
docker run -d -p 8080:8080 hasphp-app# .env file
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourapp.com
# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hasphp
DB_USERNAME=root
DB_PASSWORD=
# OpenSwoole Settings
SWOOLE_WORKERS=4
SWOOLE_TASK_WORKERS=2
SWOOLE_MAX_CONNECTIONS=1000// openswoole-server.php
$server->set([
'worker_num' => env('SWOOLE_WORKERS', 4),
'task_worker_num' => env('SWOOLE_TASK_WORKERS', 2),
'max_request' => 10000,
'max_conn' => env('SWOOLE_MAX_CONNECTIONS', 1000),
'daemonize' => env('SWOOLE_DAEMON', false),
'enable_coroutine' => true,
'hook_flags' => SWOOLE_HOOK_ALL,
]);HasPHP automatically generates OpenAPI 3.0 documentation for your APIs:
- π Auto-generated: Scans routes and generates docs
- π§ͺ Interactive: Test APIs directly in browser
- π Schema validation: Request/response validation
- π¨ Beautiful UI: Clean Swagger interface
- Main docs:
/api/docs - OpenAPI spec:
/api/docs/openapi.json - Alternative:
/docsor/swagger
{
"success": true,
"data": [
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"created_at": "2024-01-15T10:30:00Z"
}
],
"pagination": {
"total": 100,
"limit": 10,
"offset": 0,
"has_more": true
}
}FROM openswoole/swoole:php8.2-alpine
WORKDIR /var/www
COPY . .
RUN composer install --no-dev --optimize-autoloader
EXPOSE 8080
CMD ["php", "artisan", "server:start", "--daemon"]# docker-compose.yml
version: '3.8'
services:
hasphp:
build: .
ports:
- "8080:8080"
environment:
- APP_ENV=production
- DB_HOST=db
depends_on:
- db
db:
image: mysql:8.0
environment:
MYSQL_DATABASE: hasphp
MYSQL_ROOT_PASSWORD: secret# nginx configuration
upstream hasphp_backend {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
}
server {
listen 80;
server_name yourapp.com;
location / {
proxy_pass http://hasphp_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}We welcome contributions! Please see our Contributing Guide for details.
# Clone repository
git clone https://github.com/your-org/hasphp.git
cd hasphp
# Install dependencies
composer install
# Run tests
php artisan test
# Start development server
php artisan serve --port=8080- PSR-4 autoloading
- PSR-12 coding style
- PHPUnit for testing
- PHPStan for static analysis
HasPHP is open-sourced software licensed under the MIT license.
- OpenSwoole - High-performance async PHP runtime
- Twig - Flexible template engine
- Alpine.js - Lightweight reactive framework
- Swagger UI - API documentation interface
- π Documentation: hasphp.dev
- π¬ Community: Discord
- π Issues: GitHub Issues
- π§ Email: [email protected]
Built with β€οΈ by the HasPHP Team
β Star us on GitHub β’ π¦ Follow on Twitter β’ π Read the Docs