Skip to content

Commit 6870bde

Browse files
authored
[php] Laravel Workerman (#7626)
* Laravel Workerman * Small change to run CI * [ci skip] Add display_name * Change name index-man.php to start.php * Small change to rerun CI
1 parent ad4fdc0 commit 6870bde

File tree

6 files changed

+238
-0
lines changed

6 files changed

+238
-0
lines changed

frameworks/PHP/laravel/benchmark_config.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@
9292
"display_name": "laravel-roadrunner",
9393
"notes": "",
9494
"versus": "swoole"
95+
},
96+
"workerman": {
97+
"json_url": "/json",
98+
"db_url": "/db",
99+
"query_url": "/queries/",
100+
"fortune_url": "/fortunes",
101+
"update_url": "/updates/",
102+
"plaintext_url": "/plaintext",
103+
"port": 8080,
104+
"approach": "Realistic",
105+
"classification": "Fullstack",
106+
"database": "MySQL",
107+
"framework": "laravel",
108+
"language": "PHP",
109+
"flavor": "PHP8.1",
110+
"orm": "Full",
111+
"platform": "workerman",
112+
"webserver": "None",
113+
"os": "Linux",
114+
"database_os": "Linux",
115+
"display_name": "laravel-workerman",
116+
"notes": "",
117+
"versus": "php"
95118
}
96119
}]
97120
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#zend_extension=opcache.so
2+
opcache.enable=1
3+
opcache.enable_cli=1
4+
opcache.validate_timestamps=0
5+
opcache.save_comments=0
6+
opcache.enable_file_override=1
7+
opcache.huge_code_pages=1
8+
9+
mysqlnd.collect_statistics = Off
10+
11+
memory_limit = 512M
12+
13+
opcache.jit_buffer_size = 128M
14+
opcache.jit = tracing
15+
16+
disable_functions=header,header_remove,headers_sent,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,set_time_limit
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "laravel/laravel",
3+
"type": "project",
4+
"description": "The Laravel Framework.",
5+
"keywords": [
6+
"framework",
7+
"laravel"
8+
],
9+
"license": "MIT",
10+
"require": {
11+
"php": "^8.0",
12+
"laravel/framework": "^8.0",
13+
"joanhey/adapterman": "0.4"
14+
},
15+
"require-dev": {
16+
"facade/ignition": "^2.3.6",
17+
"fzaninotto/faker": "^1.9.1",
18+
"mockery/mockery": "^1.3.1",
19+
"nunomaduro/collision": "^5.0",
20+
"phpunit/phpunit": "^9.3"
21+
},
22+
"config": {
23+
"optimize-autoloader": true,
24+
"preferred-install": "dist",
25+
"sort-packages": true
26+
},
27+
"extra": {
28+
"laravel": {
29+
"dont-discover": []
30+
}
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"App\\": "app/"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"Tests\\": "tests/"
40+
}
41+
},
42+
"minimum-stability": "dev",
43+
"prefer-stable": true,
44+
"scripts": {
45+
"post-autoload-dump": [
46+
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
47+
"@php artisan package:discover --ansi"
48+
],
49+
"post-root-package-install": [
50+
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
51+
],
52+
"post-create-project-cmd": [
53+
"@php artisan key:generate --ansi"
54+
]
55+
}
56+
}
57+
58+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM ubuntu:22.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
6+
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
7+
RUN apt-get update -yqq > /dev/null && \
8+
apt-get install -yqq git unzip \
9+
php8.1-cli php8.1-mysql php8.1-mbstring php8.1-xml php8.1-curl > /dev/null
10+
11+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
12+
13+
RUN apt-get install -y php-pear php8.1-dev libevent-dev > /dev/null
14+
RUN pecl install event-3.0.8 > /dev/null && echo "extension=event.so" > /etc/php/8.1/cli/conf.d/event.ini
15+
16+
ADD ./ /laravel
17+
WORKDIR /laravel
18+
19+
EXPOSE 8080
20+
21+
RUN mkdir -p /laravel/bootstrap/cache /laravel/storage/logs /laravel/storage/framework/sessions /laravel/storage/framework/views /laravel/storage/framework/cache
22+
RUN chmod -R 777 /laravel
23+
24+
COPY deploy/workerman/composer.json ./
25+
RUN composer install --optimize-autoloader --classmap-authoritative --no-dev
26+
RUN php artisan optimize
27+
28+
COPY deploy/conf/cli-php.ini /etc/php/8.1/cli/php.ini
29+
30+
#RUN sed -i 's|$app->run();|//$app->run();|g' index.php
31+
#RUN sed -i 's|//PDO::ATTR_EMULATE_PREPARES|PDO::ATTR_EMULATE_PREPARES|g' index.php
32+
33+
CMD php server-man.php start

frameworks/PHP/laravel/server-man.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
require_once __DIR__ . '/vendor/autoload.php';
3+
4+
5+
use Adapterman\Adapterman;
6+
use Workerman\Worker;
7+
use Workerman\Lib\Timer;
8+
9+
Adapterman::init();
10+
11+
$http_worker = new Worker('http://0.0.0.0:8080');
12+
$http_worker->count = (int) shell_exec('nproc') * 4;
13+
$http_worker->name = 'AdapterMan-Laravel';
14+
$http_worker->onWorkerStart = function () {
15+
Header::$date = gmdate('D, d M Y H:i:s').' GMT';
16+
Timer::add(1, function() {
17+
Header::$date = gmdate('D, d M Y H:i:s').' GMT';
18+
});
19+
//init();
20+
require __DIR__.'/start.php';
21+
};
22+
23+
$http_worker->onMessage = static function ($connection, $request) {
24+
25+
$connection->send(run());
26+
};
27+
28+
Worker::runAll();
29+
30+
class Header {
31+
public static $date;
32+
}

frameworks/PHP/laravel/start.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/**
4+
* Laravel - A PHP Framework For Web Artisans
5+
*
6+
* @package Laravel
7+
* @author Taylor Otwell <[email protected]>
8+
*/
9+
10+
define('LARAVEL_START', microtime(true));
11+
12+
/*
13+
|--------------------------------------------------------------------------
14+
| Register The Auto Loader
15+
|--------------------------------------------------------------------------
16+
|
17+
| Composer provides a convenient, automatically generated class loader for
18+
| our application. We just need to utilize it! We'll simply require it
19+
| into the script here so that we don't have to worry about manual
20+
| loading any of our classes later on. It feels great to relax.
21+
|
22+
*/
23+
24+
require __DIR__.'/vendor/autoload.php';
25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Turn On The Lights
29+
|--------------------------------------------------------------------------
30+
|
31+
| We need to illuminate PHP development, so let us turn on the lights.
32+
| This bootstraps the framework and gets it ready for use, then it
33+
| will load up this application so that we can run it and send
34+
| the responses back to the browser and delight our users.
35+
|
36+
*/
37+
38+
$app = require_once __DIR__.'/bootstrap/app.php';
39+
40+
/*
41+
|--------------------------------------------------------------------------
42+
| Run The Application
43+
|--------------------------------------------------------------------------
44+
|
45+
| Once we have the application, we can handle the incoming request
46+
| through the kernel, and send the associated response back to
47+
| the client's browser allowing them to enjoy the creative
48+
| and wonderful application we have prepared for them.
49+
|
50+
*/
51+
52+
global $kernel;
53+
54+
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
55+
56+
57+
function run()
58+
{
59+
global $kernel;
60+
61+
ob_start();
62+
try {
63+
$response = $kernel->handle(
64+
$request = Illuminate\Http\Request::capture()
65+
);
66+
67+
$response->send();
68+
header('Date: ' . Header::$date); // To pass the bench, nginx auto add it
69+
70+
$kernel->terminate($request, $response);
71+
} catch (Throwable $e) {
72+
echo $e->getMessage();
73+
}
74+
75+
return ob_get_clean();
76+
}

0 commit comments

Comments
 (0)