Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
MongoDB command in PHP (db.serverStatus().uptime)

Im trying to get the uptime from a remote server, so far im able to get the version through the execution of a command. But I can't get it to run this command to get the uptime.

<?php
    
    
    $mongo = new MongoClient('mongodb://<user>:<pass>@<DNS>:<PORT>');
    
    echo "Connection to database successfully\n";
    
    $admin = $mongo->admin;
    
    $cursor= $admin->command(array('serverStatus().uptime'));
    
    var_dump($cursor);
    
    $response = $cursor->toArray();
    
    var_dump($response);
    
?>

Im running a var_dump to see what it returns, it does return a int but is far too big to be the actual uptime.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To get the server uptime, execute serverStatus command and then you can fetch uptime in milliseconds like this

try {
    $dsn = "mongodb://username:password@127.0.0.1:27017/";
    
    $manager = new MongoDB\Driver\Manager($dsn);
    $command = new MongoDB\Driver\Command(['serverStatus' => 1]);
    $cursor = $manager->executeCommand('admin', $command);

    foreach ($cursor->toArray() as $server) {
        //print_r($server->uptime / 60. " Minutes");
        //print_r($server->uptime / 3600. " Hours");
        print_r($server->uptime / 86400. " Days");
    }
} catch (\MongoDB\Driver\Exception\Exception $e) {  
    print_r($e);
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda