Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.0 as composer
FROM composer:2.0 AS composer

ARG TESTING=false
ENV TESTING=$TESTING
Expand All @@ -11,7 +11,7 @@ COPY composer.json /usr/local/src/
RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist

FROM appwrite/base:0.9.0 as final
FROM appwrite/base:0.9.0 AS final

LABEL maintainer="team@appwrite.io"

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
dns-server:
image: dns-dev
Expand Down
11 changes: 11 additions & 0 deletions src/DNS/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ abstract public function start(): void;
* @return string
*/
abstract public function getName(): string;

/**
* Worker Start Callback (optional for adapters that support it)
*
* @param callable $callback
*/
public function onWorkerStart(callable $callback): void
{
// Default implementation does nothing
// Adapters that support worker events should override this
}
}
15 changes: 15 additions & 0 deletions src/DNS/Adapter/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ public function getName(): string
{
return 'native';
}

/**
* Worker start callback
*
* @param callable $callback
* @return void
*/
public function onWorkerStart(callable $callback): void
{
if (is_callable($callback)) {
call_user_func($callback, $this->server, 0); // Pass dummy worker ID
} else {
throw new Exception('Worker start callback must be callable.');
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
24 changes: 24 additions & 0 deletions src/DNS/Adapter/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Swoole extends Adapter
protected Server $server;
protected string $host;
protected int $port;
protected $workerStartCallback = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add type annotation for the property.

The $workerStartCallback property lacks type specification, causing static analysis failures.

Apply this diff to fix the type annotation:

-protected $workerStartCallback = null;
+protected ?callable $workerStartCallback = null;
🧰 Tools
🪛 GitHub Actions: CodeQL

[error] 13-13: PHPStan: Property Utopia\DNS\Adapter\Swoole::$workerStartCallback has no type specified.

🤖 Prompt for AI Agents
In src/DNS/Adapter/Swoole.php at line 13, the property $workerStartCallback
lacks a type annotation, causing static analysis issues. Add an appropriate type
declaration to the property, such as specifying it as a callable or nullable
callable, to ensure proper type checking and resolve the static analysis
failures.


public function __construct(string $host = '0.0.0.0', int $port = 53)
{
Expand All @@ -32,6 +33,29 @@ public function onPacket(callable $callback): void
});
}

/**
* Set callback for worker start event
*
* @param callable $callback
*/
public function onWorkerStart(callable $callback): void
{
$this->workerStartCallback = $callback;
$this->server->on('WorkerStart', function ($server, $workerId) use ($callback) {
call_user_func($callback, $server, $workerId);
});
}

/**
* Get the server instance for configuration
*
* @return Server
*/
public function getServer(): Server
{
return $this->server;
}

/**
* Start the DNS server
*/
Expand Down
4 changes: 4 additions & 0 deletions src/DNS/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public function start(): void

Console::success('[DNS] Server is ready to accept connections');

$this->adapter->onWorkerStart(function ($server, $workerId) {
Console::info("[WORKER] Worker #{$workerId} - PID: " . getmypid() . " - Started at " . date('Y-m-d H:i:s T') . ' Memory: ' . round(memory_get_usage(true) / 1024 / 1024, 2) . "MB");
});

$this->adapter->onPacket(function (string $buffer, string $ip, int $port) {
$startTime = microtime(true);
try {
Expand Down
Loading