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

formatting #735

Merged
merged 1 commit into from
Mar 25, 2022
Merged
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: 11 additions & 17 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
use Workerman\Connection\ConnectionInterface;
use Workerman\Connection\TcpConnection;
use Workerman\Connection\UdpConnection;
use Workerman\Timer;
use Workerman\Events\Select;
use \Exception;
use Exception;


/**
Expand Down Expand Up @@ -334,12 +333,12 @@ class Worker
*/
protected $_socketName = '';

/** parse from _socketName avoid parse again in master or worker
/**
* parse from _socketName avoid parse again in master or worker
* LocalSocket The format is like tcp://0.0.0.0:8080
* @var string
*/

protected $_localSocket=null;
protected $_localSocket = null;

/**
* Context of socket.
Expand Down Expand Up @@ -726,9 +725,9 @@ protected static function initId()
{
foreach (static::$_workers as $worker_id => $worker) {
$new_id_map = [];
$worker->count = $worker->count < 1 ? 1 : $worker->count;
$worker->count = max($worker->count, 1);
for($key = 0; $key < $worker->count; $key++) {
$new_id_map[$key] = isset(static::$_idMap[$worker_id][$key]) ? static::$_idMap[$worker_id][$key] : 0;
$new_id_map[$key] = static::$_idMap[$worker_id][$key] ?? 0;
}
static::$_idMap[$worker_id] = $new_id_map;
}
Expand Down Expand Up @@ -972,7 +971,7 @@ protected static function parseCommand()
$start_time = \time();
// Check master process is still alive?
while (1) {
$master_is_alive = $master_pid && \posix_kill((int) $master_pid, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$master_pid is already int

$master_is_alive = $master_pid && \posix_kill($master_pid, 0);
if ($master_is_alive) {
// Timeout?
if (!static::$_gracefulStop && \time() - $start_time >= $timeout) {
Expand Down Expand Up @@ -1003,9 +1002,7 @@ protected static function parseCommand()
\posix_kill($master_pid, $sig);
exit;
default :
if (isset($command)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$command never is null. because line 886.

static::safeEcho('Unknown command: ' . $command . "\n");
}
static::safeEcho('Unknown command: ' . $command . "\n");
exit($usage);
}
}
Expand Down Expand Up @@ -1047,7 +1044,7 @@ protected static function formatStatusData($statistics_file)
$total_timers = 0;
$maxLen1 = static::$_maxSocketNameLength;
$maxLen2 = static::$_maxWorkerNameLength;
foreach($info as $key => $value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$key is not used.

foreach($info as $value) {
if (!$read_process_status) {
$status_str .= $value . "\n";
if (\preg_match('/^pid.*?memory.*?listening/', $value)) {
Expand Down Expand Up @@ -1354,7 +1351,7 @@ protected static function forkWorkersForWindows()
if(\count(static::$_workers) > 1)
{
static::safeEcho("@@@ Error: multi workers init in one php file are not support @@@\r\n");
static::safeEcho("@@@ See http://doc.workerman.net/faq/multi-woker-for-windows.html @@@\r\n");
static::safeEcho("@@@ See https://www.workerman.net/doc/workerman/faq/multi-woker-for-windows.html @@@\r\n");
}
elseif(\count(static::$_workers) <= 0)
{
Expand All @@ -1373,7 +1370,7 @@ protected static function forkWorkersForWindows()
}
else
{
static::$globalEvent = new \Workerman\Events\Select();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because there is use at the top of the file

static::$globalEvent = new Select();
Timer::init(static::$globalEvent);
foreach($files as $start_file)
{
Expand Down Expand Up @@ -1462,9 +1459,6 @@ protected static function forkOneWorkerForLinux(self $worker)
{
// Get available worker id.
$id = static::getId($worker->workerId, 0);
if ($id === false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because $id's return type is int. so $id === false is never equal.

return;
}
$pid = \pcntl_fork();
// For master process.
if ($pid > 0) {
Expand Down