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

Use constant for built in transports #827

Merged
merged 1 commit into from
Oct 20, 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
12 changes: 6 additions & 6 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ class Worker
/**
* PHP built-in protocols.
*
* @var array
* @var array<string,string>
*/
protected static $_builtinTransports = [
const BUILD_IN_TRANSPORTS = [
'tcp' => 'tcp',
'udp' => 'udp',
'unix' => 'unix',
Expand Down Expand Up @@ -2249,7 +2249,7 @@ public function listen()
}

// Try to open keepalive for tcp and disable Nagle algorithm.
if (\function_exists('socket_import_stream') && static::$_builtinTransports[$this->transport] === 'tcp') {
if (\function_exists('socket_import_stream') && self::BUILD_IN_TRANSPORTS[$this->transport] === 'tcp') {
\set_error_handler(function(){});
$socket = \socket_import_stream($this->_mainSocket);
\socket_set_option($socket, \SOL_SOCKET, \SO_KEEPALIVE, 1);
Expand Down Expand Up @@ -2291,7 +2291,7 @@ protected function parseSocketAddress() {
// Get the application layer communication protocol and listening address.
list($scheme, $address) = \explode(':', $this->_socketName, 2);
// Check application layer protocol class.
if (!isset(static::$_builtinTransports[$scheme])) {
if (!isset(self::BUILD_IN_TRANSPORTS[$scheme])) {
$scheme = \ucfirst($scheme);
$this->protocol = \substr($scheme,0,1)==='\\' ? $scheme : 'Protocols\\' . $scheme;
if (!\class_exists($this->protocol)) {
Expand All @@ -2301,7 +2301,7 @@ protected function parseSocketAddress() {
}
}

if (!isset(static::$_builtinTransports[$this->transport])) {
if (!isset(self::BUILD_IN_TRANSPORTS[$this->transport])) {
throw new Exception('Bad worker->transport ' . \var_export($this->transport, true));
}
} else {
Expand All @@ -2310,7 +2310,7 @@ protected function parseSocketAddress() {
}
}
//local socket
return static::$_builtinTransports[$this->transport] . ":" . $address;
return self::BUILD_IN_TRANSPORTS[$this->transport] . ":" . $address;
}

/**
Expand Down