Skip to content

Commit feb3cfc

Browse files
committed
Add Workerman
1 parent 6db3f78 commit feb3cfc

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 install -yqq php8.5-cli php8.5-xml php8.5-zip > /dev/null
10+
11+
COPY --from=composer/composer:latest-bin --link /composer /usr/local/bin/composer
12+
13+
RUN apt-get install -y php-pear php8.5-dev libevent-dev git > /dev/null && \
14+
pecl install event-3.1.4 > /dev/null && echo "extension=event.so" > /etc/php/8.5/cli/conf.d/30-event.ini
15+
16+
WORKDIR /workerman
17+
COPY --link composer.json .
18+
RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
19+
COPY php.ini /etc/php/8.5/cli/php.ini
20+
21+
COPY --link . .
22+
23+
EXPOSE 8080
24+
25+
CMD ["php", "/workerman/server.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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Workerman\Worker;
4+
use Workerman\Protocols\Http\Response;
5+
use Workerman\Connection\TcpConnection;
6+
7+
require_once __DIR__ . '/vendor/autoload.php';
8+
9+
// #### http worker ####
10+
$http_worker = new Worker('http://0.0.0.0:8080');
11+
$http_worker->reusePort = true;
12+
$http_worker->count = (int) shell_exec('nproc');
13+
$http_worker->name = 'bench';
14+
15+
// Data received
16+
$http_worker->onMessage = static function ($connection, $request) {
17+
18+
return match($request->path()) {
19+
20+
'/echo' => $connection->send( new Response(
21+
200,
22+
['Content-Type' => 'text/plain'],
23+
implode("\n", array_map(fn($name, $value) => "$name: $value", $request->header(), $request->header())))
24+
),
25+
26+
'/cookie' => $connection->send( new Response(
27+
200,
28+
['Content-Type' => 'text/plain'],
29+
implode("\n", array_map(fn($name, $value) => "$name=$value", $request->cookie(), $request->cookie())))
30+
),
31+
32+
'/' => $connection->send( new Response(
33+
200,
34+
['Content-Type' => 'text/plain'],
35+
$request->method() === 'POST' ? $request->rawBody() : 'OK')
36+
),
37+
38+
default => null,
39+
};
40+
};
41+
42+
// Run all workers
43+
Worker::runAll();

0 commit comments

Comments
 (0)