Skip to content
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
2 changes: 1 addition & 1 deletion src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ private function generateCnonce(): string
*/
public static function encodeCredentials($username, $password): string
{
return \md5(\utf8_encode($username . ':mongo:' . $password));
return \md5($username . ':mongo:' . $password);
}
}
15 changes: 14 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Swoole\Client as SwooleClient;
use Swoole\Coroutine\Client as CoroutineClient;
use stdClass;
use Swoole\Coroutine;

class Client
{
Expand Down Expand Up @@ -78,13 +79,25 @@ public function __construct(
int $port,
string $user,
string $password,
bool $useCoroutine = true
bool $useCoroutine = false
) {
$this->id = uniqid('utopia.mongo.client');
$this->database = $database;
$this->host = $host;
$this->port = $port;

// Only use coroutines if explicitly requested and we're in a coroutine context
if ($useCoroutine) {
try {
$cid = \Swoole\Coroutine::getCid();
if ($cid === false || $cid < 0) {
$useCoroutine = false;
}
} catch (\Throwable $e) {
$useCoroutine = false;
}
}

$this->client = $useCoroutine
? new CoroutineClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP)
: new SwooleClient(SWOOLE_SOCK_TCP | SWOOLE_KEEP);
Expand Down