Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swoole): Multiple Workers in SWOOLE_BASE mode #2778

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 1 addition & 27 deletions src/DDTrace/Integrations/Swoole/SwooleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,8 @@ function (HookData $hook) use ($integration, $server, $scheme) {

public function instrumentWorkerStart(callable $callback, SwooleIntegration $integration, Server $server)
{
if ($server->mode === SWOOLE_BASE) {
return;
}

\DDTrace\install_hook(
$callback,
function (HookData $hook) use ($integration, $server) {
handle_fork();
}
);
}

public function instrumentWorkerStop(callable $callback, SwooleIntegration $integration, Server $server)
{
if ($server->mode === SWOOLE_BASE) {
return;
}

\DDTrace\install_hook(
$callback,
null,
function (HookData $hook) use ($integration, $server) {
handle_fork();
}
Expand All @@ -151,9 +132,7 @@ public function init(): int
'__construct',
null,
function ($server) use ($integration) {
foreach (['workerstart', 'workerstop', 'workerexit', 'workererror'] as $serverEvent) {
$server->on($serverEvent, function () { });
}
$server->on('workerstart', function () { });
}
);

Expand All @@ -176,11 +155,6 @@ function ($server, $scope, $args, $retval) use ($integration) {
case 'workerstart':
$integration->instrumentWorkerStart($callback, $integration, $server);
break;
case 'workerstop':
case 'workerexit':
case 'workererror':
$integration->instrumentWorkerStop($callback, $integration, $server);
break;
}

}
Expand Down
4 changes: 3 additions & 1 deletion tests/Frameworks/Swoole/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
require __DIR__ . '/../../vendor/autoload.php';

$http = new Swoole\Http\Server("0.0.0.0", 9999);

$http->set([
'worker_num' => 2
]);
$http->on('request', function ($request, $response) {
$requestUri = $request->server['request_uri'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Sapi/SwooleServer/SwooleServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function start()
public function stop()
{
error_log("[swoole-server] Stopping...");
$this->process->stop(0);
$this->process->stop(0, SIGTERM);
}

public function isFastCgi()
Expand Down
Loading