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.
Question
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.
Solution
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.
OTHER TIPS
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";