Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Comando MongoDB en PHP (db.serverStatus().uptime)

Estoy tratando de obtener el tiempo de actividad de un servidor remoto, hasta ahora no puedo obtener la versión mediante la ejecución de un comando. Pero no puedo hacer que ejecute este comando para obtener el tiempo de actividad.

 <?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); ?>

Estoy ejecutando un var_dump para ver qué devuelve, devuelve un int pero es demasiado grande para ser el tiempo de actividad real.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para obtener el tiempo de actividad del servidor, ejecute el comando serverStatus y luego puede obtener el tiempo de actividad en milisegundos como este

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!