Search code examples
phplinuxuptime

Linux uptime command inside php doesn't show anything


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.