Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Apr 22, 2024
1 parent 31f9551 commit 613d46b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"symfony/var-dumper": "^6.0"
},
"suggest": {
"ext-uuid": "For unique socket id. "
"ext-uuid": "For unique socket id. ",
"workerman/redis": "Used instead of \"workerman/channel\" to improve performance"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 37 additions & 1 deletion src/ChannelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@

class ChannelClient extends \Channel\Client
{
/**
*
* @return bool
*/
public static function isChannelEnv(): bool
{
return !class_exists("\Workerman\Redis\Client", false);
}

/**
* @param $ip
* @param $port
* @return void
* @throws Exception
*/
public static function connect($ip = '127.0.0.1', $port = 2206): void
{
if (self::isChannelEnv()) {
parent::connect($ip, $port);
} else {

}
}

public static function on($event, $callback): void
{
if (self::isChannelEnv()) {
parent::on($event, $callback);
} else {
// todo redis pub sub
}
}

/**
* @param $events
* @param $data
Expand All @@ -29,7 +62,10 @@ protected static function sendAnyway($data): ?bool
self::connect(self::$_remoteIp, self::$_remotePort);
$body = serialize($data);
if (self::$_isWorkermanEnv) {
return self::$_remoteConnection->send($body);
if (self::isChannelEnv()) {
return self::$_remoteConnection->send($body);
}
// todo redis pub sub
} else {
throw new Exception('Not workerman env. ');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Events/ClientEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function response(Server $pushServer, TcpConnection $connection, array $r
return;
}
// 事件必须以client-为前缀
if (strpos($this->getEvent(), 'client-') !== 0) {
if (!str_starts_with($this->getEvent(), 'client-')) {
$pushServer->error($connection, null, 'Client event rejected - client events must be prefixed by \'client-\'');
return;
}
Expand Down

0 comments on commit 613d46b

Please sign in to comment.