当前位置:Gxlcms > PHP教程 > 将linux运行时间格式成易读格式的php代码

将linux运行时间格式成易读格式的php代码

时间:2021-07-01 10:21:17 帮助过:31人阅读

  1. $exec = shell_exec('uptime');
  2. $uptime = explode(' up ', $exec);
  3. $uptime = explode(',', $uptime[1]);
  4. if (strpos($uptime[0], 'day')) {
  5. $time = explode(':', $uptime[1]);
  6. echo('Current system uptime is ' . $uptime[0]. ', ' . $time[0] . ' hours, ' . $time[1] . ' minutes');
  7. } elseif (strpos($uptime[0], ':')) {
  8. $time = explode(':', $uptime[0]);
  9. echo('Current system uptime is ' . $time[0] . ' hours, ' . $time[1] . ' minutes');
  10. } else {
  11. $time = explode(' ', $uptime[0]);
  12. echo('Current system uptime is ' . $time[0] . ' minutes');
  13. }
  14. ?>

易读, linux, php

人气教程排行