php中的Linux正常运行时间命令;我什么也不展示


Linux uptime command inside php doesn't show anything

我正在服务器上的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似乎没有运行该命令。如果我转到命令提示符并运行正常运行时间,我会看到结果。

我正在对Linux Web服务器执行ssh操作。php文件位于我在服务器上的文件夹中。

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

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

在php中执行系统命令时,我建议您始终提供命令的完整路径。

Linux服务器的正常运行时间可以使用/proc/uptime 在PHP中轻松获得

$uptimeseconds = (int)shell_exec('cat /proc/uptime');
echo "This server has been running for $uptimeseconds seconds.'n";