Skip to content

Commit

Permalink
clean up useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Dec 11, 2023
1 parent 576fa52 commit 7a590e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 43 deletions.
5 changes: 1 addition & 4 deletions src/core/Coroutine/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
use Swoole\Coroutine\Server\Connection;
use Swoole\Exception;

/* compatibility constant */
define('SWOOLE_COROUTINE_SOCKET_HAVE_SSL_HANDSHAKE', method_exists(Socket::class, 'sslHandshake'));

class Server
{
/** @var string */
Expand Down Expand Up @@ -116,7 +113,7 @@ public function start(): bool
$conn = $socket->accept();
if ($conn) {
$conn->setProtocol($this->setting);
if (SWOOLE_COROUTINE_SOCKET_HAVE_SSL_HANDSHAKE && !empty($this->setting[Constant::OPTION_OPEN_SSL])) {
if (!empty($this->setting[Constant::OPTION_OPEN_SSL])) {
$fn = static function ($fn, $connection) {
/* @var $connection Connection */
if (!$connection->exportSocket()->sslHandshake()) {
Expand Down
18 changes: 4 additions & 14 deletions src/core/Server/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ function (Server $server, string $msg) {
'gc_status',
$accepted_process_types,
function (Server $server, string $msg) {
$status = function_exists('gc_status') ? gc_status() : [];
return self::json($status);
return self::json(gc_status());
}
);

Expand Down Expand Up @@ -528,7 +527,7 @@ public static function handlerGetResources(Server $server, string $msg)
$list = [];
foreach ($resources as $r) {
$info = [
'id' => function_exists('get_resource_id') ? get_resource_id($r) : intval($r),
'id' => get_resource_id($r),
'type' => get_resource_type($r),
];
if ($info['type'] == 'stream') {
Expand All @@ -547,16 +546,14 @@ public static function handlerGetWorkerInfo(Server $server, string $msg)
$info = [
'id' => $server->getWorkerId(),
'pid' => $server->getWorkerPid(),
'gc_status' => function_exists('gc_status') ? gc_status() : [],
'gc_status' => gc_status(),
'memory_usage' => memory_get_usage(),
'memory_real_usage' => memory_get_usage(true),
'process_status' => self::getProcessStatus(),
'coroutine_stats' => Coroutine::stats(),
'timer_stats' => Timer::stats(),
'vm_status' => swoole_get_vm_status(),
];
if (function_exists('swoole_get_vm_status')) {
$info['vm_status'] = swoole_get_vm_status();
}
return self::json($info);
}

Expand Down Expand Up @@ -611,9 +608,6 @@ public static function handlerGetCoroutineList(Server $server, string $msg)

public static function handlerGetObjects(Server $server, string $msg)
{
if (!function_exists('swoole_get_objects')) {
return self::json(['require ext-swoole_plus'], 5000);
}
$list = [];
$objects = swoole_get_objects();
foreach ($objects as $o) {
Expand Down Expand Up @@ -861,10 +855,6 @@ public static function handlerGetFunctionInfo(Server $server, string $msg)

public static function handlerGetObjectByHandle(Server $server, string $msg)
{
if (!function_exists('swoole_get_object_by_handle')) {
return self::json(['require ext-swoole_plus'], 5000);
}

$json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);
if (empty($json) || empty($json['object_id']) || empty($json['object_hash'])) {
return self::json(['error' => 'Params Error!'], 4004);
Expand Down
10 changes: 5 additions & 5 deletions src/core/Server/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Swoole\Server;

use Swoole\Constant;
use Swoole\Coroutine;
use Swoole\Server;
use Swoole\Timer;

use function Swoole\Coroutine\go;

class Helper
{
public const STATS_TIMER_INTERVAL_TIME = 1000;
Expand Down Expand Up @@ -266,10 +266,10 @@ public static function onWorkerStop(Server $server, int $workerId)
{
}

public static function onStart(Server $server)
public static function onStart(Server $server): void
{
if (!empty($server->setting['admin_server'])) {
go(function () use ($server) {
if (!empty($server->setting[Constant::OPTION_ADMIN_SERVER])) {
Coroutine::create(function () use ($server): void {
Admin::start($server);
});
}
Expand Down
20 changes: 0 additions & 20 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,3 @@ function swoole_container_cpu_num()
}
return intval(floor($cpu_num));
}

if (!function_exists('array_key_last')) {
function array_key_last(array $array)
{
if (!empty($array)) {
return key(array_slice($array, -1, 1, true));
}
return null;
}
}

if (!function_exists('array_key_first')) {
function array_key_first(array $array)
{
foreach ($array as $key => $unused) {
return $key;
}
return null;
}
}

0 comments on commit 7a590e9

Please sign in to comment.