Introducing Hypervel: A Coroutine Framework for Laravel Artisans

Last updated on by

Introducing Hypervel: A Coroutine Framework for Laravel Artisans image

Hypervel is a high-performance PHP framework inspired by Laravel, offering native coroutine support for developers building high-concurrency and I/O-intensive applications. Created by Albert Chen, it is an unofficial framework that adopts Laravel’s elegant development experience while leveraging Swoole's asynchronous capabilities.

Since there's Octane package maintained by the official team, why do we need a new framework? It may not seem wise to reinvent the wheel, does it?

Why not Octane?

While Octane impressively speeds up Laravel's performance by running the application in the long-lived lifecycle, which eliminates the cost for bootstrapping the framework each request, it can't solve performance issues brought by blocking I/O.

For example, imagine building an AI-powered chatbot with Laravel. Let's say each conversation API takes only 3~5 seconds to respond. If you run your Octane application with 10 workers, how many requests can your application handle at the same time if there are 100 concurrent requests? The QPS (Queries per Second) for your application will be less than 3. Why is this happening?

This occurs because Octane doesn't provide non-blocking I/O capabilities to Laravel. All the workers remain blocked until the end of these I/O requests. Furthermore, due to backward compatibility constraints of the current framework, Laravel has less possibility to support coroutine features in the near future.

You can refer to this issue for more details.

Features of Hypervel

Hypervel is built on Swoole extension, and all components support coroutines out of the box. Hypervel ports many core packages from Laravel while maintaining familiar usage patterns, making it instantly accessible to Laravel developers.

This framework combines the elegant and expressive development experience of Laravel with the powerful performance benefits of coroutine-based programming. If you're a Laravel developer, you'll feel right at home with this framework, requiring minimal learning curve.

You can find more practical code examples in Coding Like in Laravel.

Here are some key features:

  • Development experience extremely similar to Laravel.
  • Extremely high performance, with QPS 10 times higher than Octane in non-I/O scenarios, and hundreds of times higher in I/O-intensive scenarios.
  • Coroutine support out out the box, with even PHP's built-in I/O functions automatically being hooked to support coroutinies.
  • Support for object pools and connection pools, such as database, redis and http clients
  • Seamless two-way communication with your existing Laravel projects through Cache, Lock, and Queue.
  • Coroutine support not limited to handling HTTP requests. Queue and Scheduling can also leverage coroutines, allowing a single process to achieve the concurrency that would require hundreds of workers in Laravel.

This is an ideal choice for building microservices, API gateways, and high-concurrency applications where traditional PHP frameworks often encounter performance constraints.

Coroutines

Coroutines are functions that can pause their execution and later resume from where they left off, maintaining their state between pauses. Think of them as functions with multiple entry and exit points.

When a coroutine encounters an operation that would normally block (like waiting for network data), instead of blocking the entire program, it yields control back to a scheduler. The scheduler can then run other coroutines until the blocking operation completes.

In Hypervel, I/O components such as database connections, file operations, HTTP clients, and even all native PHP I/O functions work as coroutines. The overhead for each coroutine is extremely lightweight compared to processes or threads, making them ideal for concurrent I/O operations. This architecture enables Hypervel to perform excellently in I/O-intensive scenarios.

You can learn more about how coroutine works in Hypervel in Coroutine section of the official documentation.

What's more, coroutines are not only supported in request handling. In Laravel, the only way to improve concurrency in queues or task scheduling is to increase the number of workers on the machine. But in Hypervel, you can run multiple jobs simultaneously under coroutine scheduling. This means one worker process can act as hundreds of traditional workers for I/O bound jobs in Laravel.

Benchmark

The benchmark tests cover two distinct scenarios to evaluate performance under different conditions:

  1. Simple API Test: A basic hello world API endpoint. No middleware applied.

  1. Simulated I/O Wait Test: Sleep for one second to simulate I/O wait time

Laravel Octane's QPS number is close to 8, but because it differs so significantly from Hypervel's numbers, it appears this way when generated in the chart.

You can see benchmark for more detailed information.

Prerequisites

Hypervel has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:

  • PHP >= 8.2
  • Swoole PHP extension >= 5.1
  • Pcntl PHP extension

You can install Swoole extension via PECL:

pecl install swoole

Mac users can also install Swoole via brew:

brew tap shivammathur/extensions
brew install shivammathur/extensions/swoole@8.3

Using shivammathur/extensions can help you solve common issues while installing swoole on Apple M1 environments.

For full requirements, you can refer to server requirements on the website.

Installation

You can create a new Hypervel project easily via Composer's create-project command:

composer create-project hypervel/hypervel example-app

Once the project has been created, start Hypervel's local development server using serve command:

php artisan serve

Once you have started the HTTP server, your application will be accessible in your web browser at http://localhost:9501 by default.

Conclusion

Undoubtedly, Laravel is the top choice for building web applications in many use cases, especially with its mature community and rich ecosystem.

However, in some high-concurrency or intensive I/O scenarios, you can definitely give Hypervel a try for ultra performance and enjoy Laravel-like development experience at the same time.

You can get started with Hypervel by checking out the official website.

Albert Chen photo

Software architect, Laravel artisan and the creator of Hypervel framework.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Confidently Extract Single Array Items with Laravel's Arr::sole() Method image

Confidently Extract Single Array Items with Laravel's Arr::sole() Method

Read article
Safely Retry API calls in Laravel image

Safely Retry API calls in Laravel

Read article
Laravel's AsHtmlString Cast for Elegant HTML Attribute Management image

Laravel's AsHtmlString Cast for Elegant HTML Attribute Management

Read article
NativePHP for Mobile v1 — Launching May 2 image

NativePHP for Mobile v1 — Launching May 2

Read article
Map Eloquent Attributes into an Object Using the Collection Cast in Laravel 12.10 image

Map Eloquent Attributes into an Object Using the Collection Cast in Laravel 12.10

Read article
Converting Array Values to Enum Instances with Laravel's mapInto Method image

Converting Array Values to Enum Instances with Laravel's mapInto Method

Read article