HypervelHypervel
Hypervel
Documentation
GitHub
Hypervel
Documentation
GitHub
Hypervel

Hypervel

A Coroutine PHP Framework for Laravel Artisans.

Get StartedGitHub

Laravel Friendly

By porting Laravel's core infrastructure and fundamental components, this framework enables Laravel developers to quickly adapt to it.

High Performance

Leveraging Swoole's native coroutine support, it delivers exceptional performance and efficient concurrency handling.

Ecosystem Compatibility

Hypervel is compatible with the Hyperf ecosystem, sharing the same community resources and packages.

Coding Like in Laravel

Laravel artisans can enjoy a familiar development experience that mirrors the original framework. The simple, elegant syntax remains intact, enabling developers to stay productive while leveraging enhanced performance.

  • Authentication
  • Authorization
  • Eloquent ORM
  • Database Migrations
  • Validation
  • Notification and Email
  • File Storage
  • Job Queues
  • Task Scheduling
  • Testing
  • Events

Authentication

Authenticating users is as simple as adding an authentication middleware to your Hypervel route definition:

Route::get('/profile', ProfileController::class, [
  'middleware' => 'auth'
]);

Once the user is authenticated, you can access the authenticated user via the Auth facade:

use Hypervel\Support\Facades\Auth;

$user = Auth::user();

Of course, you may define your own authentication middleware, allowing you to customize the authentication process.

Read Authentication docs

Authorization

You'll often need to check whether an authenticated user is authorized to perform a specific action. Hypervel's model policies make it a breeze:

php artisan make:policy UserPolicy

Once you've defined your authorization rules in the generated policy class, you can authorize the user's request in your controller methods:

public function update(Request $request, Invoice $invoice)
{
    Gate::authorize('update', $invoice);

    $invoice->update(/* ... */);
}

Read Authorization docs

Eloquent

Scared of databases? Don't be. Hypervel’s Eloquent ORM makes it painless to interact with your application's data, and models, migrations, and relationships can be quickly scaffolded:

php artisan make:model Invoice --migration

Once you've defined your model structure and relationships, you can interact with your database using Eloquent's powerful, expressive syntax:

// Create a related model...
$user->invoices()->create(['amount' => 100]);

// Update a model...
$invoice->update(['amount' => 200]);

// Retrieve models...
$invoices = Invoice::unpaid()->where('amount', '>=', 100)->get();

// Rich API for model interactions...
$invoices->each->pay();

Read Eloquent docs

Database Migrations

Migrations are like version control for your database, allowing your team to define and share your application's database schema definition:

return new class extends Migration {
    public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table->uuid()->primary();
            $table->foreignUuid('airline_id')->constrained();
            $table->string('name');
            $table->timestamps();
        });
    }
};

Read Migration docs

Validation

Laravel has over 90 powerful, built-in validation rules and, using Hypervel Precognition, can provide live validation on your frontend:

public function update(Request $request)
{
    $validated = $request->validate([
        'email' => 'required|email|unique:users',
        'password' => Password::required()->min(8),
    ]);

    $request->user()->update($validated);
}

Read Validation docs

Notifications & Mail

Use Hypervel to quickly send beautifully styled notifications to your users via email, Slack, SMS, in-app, and more:

php artisan make:notification InvoicePaid

Once you have generated a notification, you can easily send the message to one of your application's users:

$user->notify(new InvoicePaid($invoice));

Read Notification and Mail docs

File Storage

Hypervel provides a robust filesystem abstraction layer, providing a single, unified API for interacting with local filesystems and cloud based filesystems like Amazon S3:

$path = Storage::disk('s3')
    ->put('avatars/1', $request->file('avatar'));

Regardless of where your files are stored, interact with them using Hypervel's simple, elegant syntax:

$content = Storage::get('photo.jpg');

Storage::put('photo.jpg', $content);

Read File Storage docs

Job Queues

Hypervel lets you to offload slow jobs to a background queue, keeping your web requests snappy:

$podcast = Podcast::create(/* ... */);

ProcessPodcast::dispatch($podcast)->onQueue('podcasts');

You can run as many queue workers as you need to handle your workload:

php artisan queue:work redis --queue=podcasts

Read Queues docs

Task Scheduling

Schedule recurring jobs and commands with an expressive syntax and say goodbye to complicated configuration files:

$schedule->job(NotifySubscribers::class)->hourly();

Hypervel's scheduler can even handle multiple servers and offers built-in overlap prevention:

$schedule->job(NotifySubscribers::class)
    ->dailyAt('9:00')
    ->onOneServer()
    ->withoutOverlapping();

Read Task Scheduling docs

Testing

Hypervel is built for testing. From unit tests to feature tests, you’ll feel more confident in deploying your application:

class RefreshDatabaseTest extends TestCase
{
    use RefreshDatabase;

    public function testCreateUser()
    {
        $user = factory(User::class)->create();

        $this->assertDatabaseHas('users', [
            'id' => $user->id,
        ]);
    }
}

Read Testing docs

Events & Websockets

Hypervel's events allow you to send and listen for events across your application, and listeners can easily be dispatched to a background queue:

OrderShipped::dispatch($order);
class SendShipmentNotification implements ShouldQueue
{
    public function handle(OrderShipped $event): void
    {
        // ...
    }
}

Your frontend application can even subscribe to your Hypervel events using Laravel Echo and WebSockets, allowing you to build real-time, dynamic applications:

Echo.private(`orders.${orderId}`)
    .listen('OrderShipped', (e) => {
        console.log(e.order);
    });

Read Events docs

Blazingly Fast

The concurrency capability of Hypervel is at least ten times better than traditional Laravel Octane and also offers lower response latency, which makes it an excellent choice for building web applications in high concurrency use cases.

For more detailed benchmark, please see here.

  • Laravel Octane
Running 10s test @ http://127.0.0.1:8000/api
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    15.93ms   16.86ms 155.82ms   87.02%
    Req/Sec     2.07k   420.46     3.10k    66.00%
  82661 requests in 10.04s, 16.95MB read
Requests/sec:   8230.97
Transfer/sec:      1.69MB
  • Hypervel
Running 10s test @ http://127.0.0.1:9501/api
  4 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.66ms   17.85ms 249.92ms   90.25%
    Req/Sec    24.42k    10.47k   54.37k    68.53%
  971692 requests in 10.06s, 151.98MB read
Requests/sec:  96562.80
Transfer/sec:     15.10MB

Native Coroutine Support

Unlike other async libraries such as AMPHP or ReactPHP, where developers must rewrite every blocking I/O client in their applications to avoid blocking the event loop, this means you can't utilize the current PHP ecosystem, such as Guzzle, PDO, Redis clients, or other native PHP functions.

See: How can I use blocking functions? in ReactPHP.

All components in Hypervel support coroutines out of the box. Even better, Hypervel can seamlessly transform PHP's built-in blocking I/O functions into coroutines, thanks to Swoole's runtime hooks.

use Hypervel\Coroutine\Coroutine;
use Hypervel\Support\Facades\Http;

Coroutine::create(function () {
    // It won't block the main process
    $response = Http::get('https://hypervel.org');
    // Even built-in blocking functions will become coroutines
    sleep(1);
    echo $response->body();
});

// This line will be printed first
echo 'Hello world!' . PHP_EOL;

See Coroutine for more detailed information.

Frequently Asked Questions

Is Hypervel compatible with Laravel packages?

No! While Hypervel maintains the similar development experience like Laravel, unfortunately, you can't install Laravel packages on this framework due to the fundamental differences in architecture. Developers need to migrate these Laravel packages on their own. We encourage developers to contribute to Hypervel's ecosystem together.

How does Hypervel achieve high performance?

Hypervel achieves high performance through Swoole's coroutine system, which enables non-blocking I/O operations and efficient concurrency handling. This allows the framework to handle more concurrent connections with fewer resources compared to traditional PHP-FPM.

Why not use Octane directly?

Octane accelerates Laravel by maintaining the framework in a persistent application state, resetting request-scoped resources between requests. However, it doesn't introduce non-blocking I/O capabilities to Laravel's architecture. Furthermore, all components in Laravel weren't designed with coroutines in mind. It will cause states bleeding while context switching among coroutines.

For I/O-intensive scenarios, even with Octane's improvements, your application's ability to handle concurrent requests is still limited by the duration of these I/O operations.

Should I migrate my current Laravel projects to Hypervel?

If you don't have performance issues in your current projects, I would suggest remaining in Laravel because of the mature community and rich ecosystem. There will be necessary refactorings for the migration process. You can consider migrating only the APIs and modules with performance issues to Hypervel, and adopt architecture like API Gateway to allow Laravel and Hypervel projects to work simultaneously.

MIT Licensed | Copyright © 2024-present Hypervel