Skip to content

Commit 752e097

Browse files
MDA2AVjoanhey
andauthored
Workerman (#105)
* Add Workerman * Update Dockerfile * Try to fix * Again * Large path :/ * Again * Try again * Change name * Fix dockerfile.. * adjust docker --------- Co-authored-by: joanhey <joanhey@kumbiaphp.com>
1 parent 6db3f78 commit 752e097

5 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM php:8.5-cli
2+
3+
COPY --from=composer/composer:latest-bin --link /composer /usr/local/bin/composer
4+
5+
RUN docker-php-ext-install pcntl > /dev/null
6+
RUN apt-get update -yqq && apt-get install -yqq git unzip > /dev/null && rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /workerman
9+
COPY src/Servers/WorkermanServer/composer.json .
10+
RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
11+
COPY src/Servers/WorkermanServer/php.ini /etc/php/8.5/cli/php.ini
12+
13+
COPY src/Servers/WorkermanServer/start.php .
14+
15+
EXPOSE 8080
16+
17+
CMD ["php", "/workerman/start.php", "start"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"workerman/workerman": "dev-master"
4+
},
5+
"autoload": {
6+
"psr-4": {
7+
"": "./"
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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.huge_code_pages=1
7+
8+
memory_limit = 512M
9+
opcache.jit_buffer_size=128M
10+
opcache.jit=tracing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "Workerman", "language": "PHP"}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
use Workerman\Worker;
4+
use Workerman\Protocols\Http\Response;
5+
6+
require_once __DIR__ . '/vendor/autoload.php';
7+
8+
// #### http worker ####
9+
$http_worker = new Worker('http://0.0.0.0:8080');
10+
$http_worker->reusePort = true;
11+
$http_worker->count = (int) shell_exec('nproc');
12+
$http_worker->name = 'bench';
13+
14+
// Data received
15+
$http_worker->onMessage = static function ($connection, $request) {
16+
17+
return match($request->path()) {
18+
19+
'/echo' => $connection->send( new Response(
20+
200,
21+
['Content-Type' => 'text/plain'],
22+
implode("\n", array_map(fn($name, $value) => "$name: $value", $request->header(), $request->header())))
23+
),
24+
25+
'/cookie' => $connection->send( new Response(
26+
200,
27+
['Content-Type' => 'text/plain'],
28+
implode("\n", array_map(fn($name, $value) => "$name=$value", $request->cookie(), $request->cookie())))
29+
),
30+
31+
'/' => $connection->send( new Response(
32+
200,
33+
['Content-Type' => 'text/plain'],
34+
$request->method() === 'POST' ? $request->rawBody() : 'OK')
35+
),
36+
37+
default => null,
38+
};
39+
};
40+
41+
// Run all workers
42+
Worker::runAll();

0 commit comments

Comments
 (0)