【问题标题】:Linux uptime command inside php doesn't show anythingphp中的Linux正常运行时间命令不显示任何内容
【发布时间】:2014-04-24 02:44:23
【问题描述】:

我正在尝试在服务器上的 php 文件中使用 linux 命令来获取正常运行时间,如下所示

<p> The uptime for this system is <?php $up_time=shell_exec('uptime');
echo $uptime; ?</p>

但是当我打开我的网页时,它只显示:

The uptime for this system is

PHP 似乎没有运行该命令。 如果我转到命令提示符并运行 uptime,我确实会看到结果。

我正在通过 ssh 进入 Linux 网络服务器。 php 文件位于服务器上我的文件夹中。

【问题讨论】:

  • 我认为您在实际代码中正确关闭了&lt;?php,与上面的示例不同?
  • 你试过绝对路径吗? /bin/uptime Shell_exec 将在错误时返回 null。
  • 你应该看到这个问题stackoverflow.com/questions/5882650/…

标签: php linux uptime


【解决方案1】:

我认为下面的代码会起作用。

The uptime for this system is <?php passthru('/usr/bin/uptime'); ?>

在 php 中执行系统命令,我建议你总是提供命令的完整路径。

【讨论】:

  • 嗨 - 非常感谢。它起作用了,但是我从 php 命令得到的结果与我在终端上写 uptime 得到的结果有所不同。在 php 中,我得到以下“该系统的正常运行时间是 00:21:47 77 天,9:58,0 个用户,平均负载:0.00、0.00、0.00”但在终端上我得到以下“00:21 :42 up 755 days, 22:16, 4 users, load average: 0.00, 0.00, 0.00 "你知道为什么吗?
  • 你在同一台机器上执行命令吗? 77 天
猜你喜欢
  • 1970-01-01
  • 2020-05-23
  • 1970-01-01
  • 2012-01-06
  • 2013-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多