문제

I am trying a linux command for uptime in a php file on a server as below

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

But when I open my webpage it just shows :

The uptime for this system is

PHP doesn't appear to be running the command. If I go to command prompt and run uptime, I do see the results.

I am doing ssh into a Linux webserver. The php file resides in my folder on the server.

도움이 되었습니까?

해결책

I think the following code will work.

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

executing system command in a php, I suggest you always provide the full path of the command.

다른 팁

Linux server uptime can be easily obtained in PHP using the /proc/uptime

$uptimeseconds = (int)shell_exec('cat /proc/uptime');
echo "This server has been running for $uptimeseconds seconds.\n";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top