Skip to content

Commit 6b5a302

Browse files
authored
Adds support for Hypervel (#10058)
* init hypervel * Hypervel Benchmark * Dockerfile: optimize composer installation and artisan commands * Delete useless files
1 parent d4b92e9 commit 6b5a302

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1941
-0
lines changed

frameworks/PHP/hypervel/.env

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
APP_NAME=Hypervel
2+
APP_ENV=production
3+
APP_DEBUG=false
4+
APP_KEY=base64:bZw/z/v+8K+n5GzPy/3hZkTlV/t2IOET7AGNmqO8W4E=
5+
6+
LOG_CHANNEL=stdout
7+
8+
DB_CONNECTION=mysql
9+
DB_HOST=tfb-database
10+
DB_PORT=3306
11+
DB_DATABASE=hello_world
12+
DB_USERNAME=benchmarkdbuser
13+
DB_PASSWORD=benchmarkdbpass
14+
15+
SESSION_DRIVER=array
16+
SESSION_LIFETIME=120
17+
SESSION_ENCRYPT=false
18+
SESSION_PATH=/
19+
SESSION_DOMAIN=null
20+
21+
BROADCAST_DRIVER=null
22+
23+
CACHE_DRIVER=file
24+
25+
QUEUE_DRIVER=sync
26+
27+
JWT_SECRET=

frameworks/PHP/hypervel/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<p align="center"><a href="https://hypervel.org" target="_blank"><img src="https://hypervel.org/logo.png" width="400"></a></p>
2+
3+
<p align="center">
4+
<a href="https://github.com/hypervel/hypervel/actions"><img src="https://github.com/hypervel/hypervel/workflows/tests/badge.svg" alt="Build Status"></a>
5+
<a href="https://packagist.org/packages/hypervel/framework"><img src="https://img.shields.io/packagist/dt/hypervel/framework" alt="Total Downloads"></a>
6+
<a href="https://packagist.org/packages/hypervel/hypervel"><img src="https://img.shields.io/packagist/v/hypervel/hypervel" alt="Latest Stable Version"></a>
7+
<a href="https://packagist.org/packages/hypervel/hypervel"><img src="https://img.shields.io/packagist/l/hypervel/hypervel" alt="License"></a>
8+
</p>
9+
10+
## Introduction
11+
12+
**Hypervel** is a Laravel-style PHP framework with native coroutine support for ultra-high performance.
13+
14+
Hypervel ports many core components from Laravel while maintaining familiar usage patterns, making it instantly accessible to Laravel developers. The 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.
15+
16+
This is an ideal choice for building microservices, API gateways, and high-concurrency applications where traditional PHP frameworks often encounter performance constraints.
17+
18+
## Why Hypervel?
19+
20+
While Laravel Octane impressively enhances your Laravel application's performance, it's crucial to understand the nature of modern web applications. In most cases, the majority of latency stems from I/O operations, such as file operations, database queries, and API requests.
21+
22+
However, Laravel doesn't support coroutines - the entire framework is designed for a blocking I/O environment. Applications heavily dependent on I/O operations will still face performance bottlenecks. Consider this scenario:
23+
24+
Imagine building an AI-powered chatbot where each conversation API takes 3-5 seconds to respond. With 10 workers in Laravel Octane receiving 10 concurrent requests, all workers would be blocked until these requests complete.
25+
26+
> You can see [benchmark comparison](https://hypervel.org/docs/introduction.html#benchmark) between Laravel Octane and Hypervel
27+
28+
Even with Laravel Octane's improvements, your application's concurrent request handling capacity remains constrained by I/O operation duration. Hypervel addresses this limitation through coroutines, enabling efficient handling of concurrent I/O operations without blocking workers. This approach significantly enhances performance and concurrency for I/O-intensive applications.
29+
30+
> See [this issue](https://github.com/laravel/octane/issues/765) for more discussions.
31+
32+
## Documentation
33+
34+
[https://hypervel.org/docs](https://hypervel.org/docs)
35+
36+
Hypervel provides comprehensive and user-friendly documentation that allows you to quickly get started. From this documentation, you can learn how to use various components in Hypervel and understand the differences between this framework and Laravel.
37+
38+
> Most of the content in this documentation is referenced from the official Laravel documentation. We appreciate the Laravel community's contributions.
39+
40+
## License
41+
42+
The Hypervel framework is open-sourced software licensed under the [MIT](https://opensource.org/licenses/MIT) license.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console;
6+
7+
use Hypervel\Console\Scheduling\Schedule;
8+
use Hypervel\Foundation\Console\Kernel as ConsoleKernel;
9+
10+
class Kernel extends ConsoleKernel
11+
{
12+
/**
13+
* Define the application's command schedule.
14+
*/
15+
public function schedule(Schedule $schedule): void
16+
{
17+
// $schedule->command('demo:hi')->everyFiveSeconds();
18+
}
19+
20+
public function commands(): void
21+
{
22+
$this->load(__DIR__ . '/Commands');
23+
24+
require base_path('routes/console.php');
25+
}
26+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Exceptions;
6+
7+
use Hypervel\Foundation\Exceptions\Handler as ExceptionHandler;
8+
use Hypervel\Http\Request;
9+
use Throwable;
10+
11+
class Handler extends ExceptionHandler
12+
{
13+
/**
14+
* The list of the inputs that are never flashed to the session on validation exceptions.
15+
*
16+
* @var array<int, string>
17+
*/
18+
protected array $dontFlash = [
19+
'current_password',
20+
'password',
21+
'password_confirmation',
22+
];
23+
24+
/**
25+
* Register the exception handling callbacks for the application.
26+
*/
27+
public function register(): void
28+
{
29+
// return json when path start with `api`
30+
$this->shouldRenderJsonWhen(function (Request $request, Throwable $e) {
31+
return str_starts_with($path = $request->path(), 'api')
32+
&& (strlen($path) === 3 || $path[3] === '/');
33+
});
34+
35+
$this->reportable(function (Throwable $e) {
36+
});
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers;
6+
7+
abstract class AbstractController
8+
{
9+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers;
6+
7+
use App\Models\Fortune;
8+
use App\Models\World;
9+
10+
class IndexController extends AbstractController
11+
{
12+
public function json()
13+
{
14+
return response()->json(['message' => 'Hello, World!']);
15+
}
16+
17+
public function db()
18+
{
19+
return response()->json(World::query()->find(self::randomInt()));
20+
}
21+
22+
public function queries($queries = 1)
23+
{
24+
$queries = self::clamp($queries);
25+
26+
$rows = [];
27+
while ($queries--) {
28+
$rows[] = World::query()->find(self::randomInt());
29+
}
30+
31+
return response()->json($rows);
32+
}
33+
34+
public function fortunes()
35+
{
36+
$rows = Fortune::all();
37+
38+
$insert = new Fortune();
39+
$insert->id = 0;
40+
$insert->message = 'Additional fortune added at request time.';
41+
42+
$rows->add($insert);
43+
$rows = $rows->sortBy('message');
44+
45+
return response(view('fortunes', ['rows' => $rows]), 200, ['Content-Type' => 'text/html; charset=UTF-8']);
46+
}
47+
48+
public function updates($queries = 1)
49+
{
50+
$queries = self::clamp($queries);
51+
52+
$rows = [];
53+
54+
while ($queries--) {
55+
$row = World::query()->find(self::randomInt());
56+
while (($randomInt = self::randomInt()) === $row->randomNumber) {
57+
}
58+
$row->randomNumber = $randomInt;
59+
$row->save();
60+
61+
$rows[] = $row;
62+
}
63+
64+
return response()->json($rows);
65+
}
66+
67+
public function plaintext()
68+
{
69+
return response('Hello, World!', 200, ['Content-Type' => 'text/plain']);
70+
}
71+
72+
private static function randomInt()
73+
{
74+
return random_int(1, 10000);
75+
}
76+
77+
private static function clamp($value)
78+
{
79+
if (!is_numeric($value) || $value < 1) {
80+
return 1;
81+
}
82+
if ($value > 500) {
83+
return 500;
84+
}
85+
return (int)$value;
86+
}
87+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http;
6+
7+
use Hypervel\Foundation\Http\Kernel as HttpKernel;
8+
9+
class Kernel extends HttpKernel
10+
{
11+
/**
12+
* The application's global HTTP middleware stack.
13+
*
14+
* These middleware are run during every request to your application.
15+
*
16+
* @var array<int, class-string|string>
17+
*/
18+
protected array $middleware = [
19+
// \App\Http\Middleware\TrimStrings::class,
20+
// \Hypervel\Http\Middleware\HandleCors::class,
21+
// \App\Http\Middleware\ConvertEmptyStringsToNull::class
22+
];
23+
24+
/**
25+
* The application's route middleware groups.
26+
*
27+
* @var array<string, array<int, class-string|string>>
28+
*/
29+
protected array $middlewareGroups = [
30+
'web' => [
31+
// \Hypervel\Router\Middleware\SubstituteBindings::class,
32+
// \Hypervel\Cookie\Middleware\AddQueuedCookiesToResponse::class,
33+
// \Hypervel\Session\Middleware\StartSession::class,
34+
// \Hypervel\View\Middleware\ShareErrorsFromSession::class,
35+
// \App\Http\Middleware\VerifyCsrfToken::class,
36+
],
37+
38+
'api' => [
39+
// 'throttle:60,1,api',
40+
// \Hypervel\Router\Middleware\SubstituteBindings::class,
41+
],
42+
];
43+
44+
/**
45+
* The application's middleware aliases.
46+
*
47+
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
48+
*
49+
* @var array<string, class-string|string>
50+
*/
51+
protected array $middlewareAliases = [
52+
// 'auth' => \App\Http\Middleware\Authenticate::class,
53+
// 'can' => \Hypervel\Auth\Middleware\Authorize::class,
54+
// 'throttle' => \Hypervel\Router\Middleware\ThrottleRequests::class,
55+
// 'bindings' => \Hypervel\Router\Middleware\SubstituteBindings::class,
56+
// 'signed' => \App\Http\Middleware\ValidateSignature::class,
57+
];
58+
59+
/**
60+
* The priority-sorted list of middleware.
61+
*
62+
* Forces non-global middleware to always be in the given order.
63+
*
64+
* @var string[]
65+
*/
66+
protected array $middlewarePriority = [
67+
// \Hypervel\Router\Middleware\ThrottleRequests::class,
68+
// \Hypervel\Router\Middleware\SubstituteBindings::class,
69+
// \Hypervel\Session\Middleware\StartSession::class,
70+
// \Hypervel\View\Middleware\ShareErrorsFromSession::class,
71+
// \App\Http\Middleware\VerifyCsrfToken::class,
72+
];
73+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Models;
6+
7+
use App\Models\Model;
8+
9+
class Fortune extends Model
10+
{
11+
protected ?string $table = 'Fortune';
12+
13+
public bool $timestamps = false;
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Models;
6+
7+
use Hypervel\Database\Eloquent\Model as BaseModel;
8+
9+
abstract class Model extends BaseModel
10+
{
11+
protected ?string $connection = null;
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Models;
6+
7+
use Hypervel\Foundation\Auth\User as Authenticatable;
8+
9+
class User extends Authenticatable
10+
{
11+
/**
12+
* The attributes that are mass assignable.
13+
*/
14+
protected array $fillable = [
15+
'name',
16+
'email',
17+
'email_verified_at',
18+
'password',
19+
];
20+
}

0 commit comments

Comments
 (0)