Skip to content

Commit 7455a4a

Browse files
authored
[php] Wolff add Adapterman variant (#10024)
1 parent a9f7dcd commit 7455a4a

File tree

6 files changed

+153
-4
lines changed

6 files changed

+153
-4
lines changed

frameworks/PHP/wolff/app/controllers/Home.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function fortunes(Request $req, Response $res)
101101
usort($fortunes, function ($left, $right) {
102102
return $left['message'] <=> $right['message'];
103103
});
104+
$res->setHeader('Content-Type', 'text/html; charset=utf-8');
104105
View::render('fortunes', [
105106
'fortunes' => $fortunes,
106107
]);

frameworks/PHP/wolff/benchmark_config.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"default": {
66
"json_url": "/json",
77
"plaintext_url": "/plaintext",
8-
"db_url": "/db",
9-
"query_url": "/queries?queries=",
10-
"update_url": "/update?queries=",
11-
"fortune_url": "/fortunes",
8+
"db_url": "/db",
9+
"query_url": "/queries?queries=",
10+
"update_url": "/update?queries=",
11+
"fortune_url": "/fortunes",
1212
"port": 8080,
1313
"approach": "Realistic",
1414
"classification": "Fullstack",
@@ -24,6 +24,29 @@
2424
"display_name": "Wolff",
2525
"notes": "",
2626
"versus": "php"
27+
},
28+
"workerman": {
29+
"json_url": "/json",
30+
"plaintext_url": "/plaintext",
31+
"db_url": "/db",
32+
"query_url": "/queries?queries=",
33+
"update_url": "/update?queries=",
34+
"fortune_url": "/fortunes",
35+
"port": 8080,
36+
"approach": "Realistic",
37+
"classification": "Fullstack",
38+
"database": "mysql",
39+
"framework": "Wolff",
40+
"language": "PHP",
41+
"flavor": "PHP8",
42+
"orm": "raw",
43+
"platform": "workerman",
44+
"webserver": "none",
45+
"os": "Linux",
46+
"database_os": "Linux",
47+
"display_name": "Wolff [workerman]",
48+
"notes": "",
49+
"versus": "php"
2750
}
2851
}
2952
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
opcache.enable=1
2+
opcache.enable_cli=1
3+
opcache.validate_timestamps=0
4+
opcache.save_comments=0
5+
opcache.enable_file_override=1
6+
opcache.memory_consumption=256
7+
opcache.interned_strings_buffer=16
8+
opcache.huge_code_pages=1
9+
10+
mysqlnd.collect_statistics = Off
11+
memory_limit = 512M
12+
13+
opcache.jit_buffer_size=128M
14+
opcache.jit=tracing
15+
16+
disable_functions=header,header_remove,headers_sent,headers_list,http_response_code,setcookie,session_create_id,session_id,session_name,session_save_path,session_status,session_start,session_write_close,session_regenerate_id,session_unset,session_get_cookie_params,session_set_cookie_params,set_time_limit

frameworks/PHP/wolff/public/start.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Config
5+
*/
6+
global $config;
7+
$config = require '../system/config.php';
8+
9+
if ($config['stdlib_on']) {
10+
include_once '../vendor/usbac/wolff-framework/src/stdlib.php';
11+
}
12+
13+
error_reporting($config['development_on'] ? E_ALL : 0);
14+
ini_set('display_errors', strval($config['development_on']));
15+
16+
/**
17+
* Wolff
18+
*/
19+
20+
require '../system/web.php';
21+
22+
function run(): string
23+
{
24+
global $config;
25+
ob_start();
26+
27+
$_SERVER['DOCUMENT_ROOT'] = '/wolff/bench';
28+
new Wolff\Kernel($config)->start();
29+
header(HeaderDate::$date); // To pass the bench, nginx auto add it
30+
31+
return ob_get_clean();
32+
}

frameworks/PHP/wolff/server.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
require_once __DIR__ . '/vendor/autoload.php';
3+
4+
5+
use Adapterman\Adapterman;
6+
use Workerman\Worker;
7+
use Workerman\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->reusePort = true;
14+
$http_worker->name = 'AdapterMan Wolff';
15+
16+
$http_worker->onWorkerStart = static function () {
17+
HeaderDate::init();
18+
chdir(__DIR__.'/public');
19+
require 'start.php';
20+
};
21+
22+
$http_worker->onMessage = static function ($connection) {
23+
24+
$connection->send(run());
25+
};
26+
27+
Worker::runAll();
28+
29+
class HeaderDate
30+
{
31+
const NAME = 'Date: ';
32+
33+
/**
34+
* Date header
35+
*
36+
* @var string
37+
*/
38+
public static $date;
39+
40+
public static function init(): void
41+
{
42+
self::$date = self::NAME . gmdate(DATE_RFC7231);
43+
Timer::add(1, static function() {
44+
self::$date = self::NAME . gmdate(DATE_RFC7231);
45+
});
46+
}
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM ubuntu:24.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 > /dev/null && \
7+
apt-get update -yqq > /dev/null && apt-get upgrade -yqq > /dev/null
8+
9+
RUN apt-get update -yqq > /dev/null && apt-get install -yqq git \
10+
php8.4-cli php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl > /dev/null
11+
12+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
13+
14+
RUN apt-get install -y php-pear php8.4-dev libevent-dev > /dev/null
15+
RUN pecl install event-3.1.4 > /dev/null && echo "extension=event.so" > /etc/php/8.4/cli/conf.d/event.ini
16+
17+
COPY deploy/conf/adapterman-php.ini /etc/php/8.4/cli/conf.d/20-adapterman.ini
18+
19+
WORKDIR /wolff/bench
20+
COPY --link . .
21+
22+
EXPOSE 8080
23+
24+
RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
25+
RUN composer require joanhey/adapterman:^0.7 --quiet
26+
27+
RUN chmod -R 777 /wolff
28+
29+
CMD php server.php start
30+

0 commit comments

Comments
 (0)