The missing uptime package for PHP inspired by python module uptime.
MIT License
The missing PHP uptime package inspired by python module uptime.
This package aims to provides a cross platform PHP API β OO and functional β that tells you how long your system has been up and when it booted. This turns out to be surprisingly non-straightforward across systems, but not impossible on any major platform.
Group | Systems | |
---|---|---|
π | BSD |
FreeBSD , OpenBSD , NetBSD , BSD
|
π | Linux |
Linux , Cygwin , Linux-armv71 , Linux2 , Unix , SunOS
|
π | Darwin |
Darwin , Mac , OSX
|
π | Windows |
Windows , Win32 , Winnt
|
π | OpenVMS | OpenVMS |
:octocat: | NetWare | ? |
{
"require": {
"uptime/uptime": "~0.1"
}
}
Through terminal: composer require uptime/uptime:~0.1
π±
Besides classes, this package registers two global functions: uptime
and boottime
.
$seconds = uptime(); # <float||int> uptime in seconds
$timestamp = boottime(); # <string> server boottime timestamp
For more complex manipulations you can use the OO interface:
use Uptime\System;
$system = new System(); # <Uptime\System #>
$uptime = $system->getUptime(); # <Uptime\Uptime implements \DateInterval #> {}
$uptime->d # <int> days
$uptime->h # <int> hours
$uptime->m # <int> minutes
$uptime->s # <float||int> seconds
$boottime = $system->getBoottime(); # <Uptime\Boottime implements \DateTime #> {}
$boottime->format('Ymd H:i:s'); # <string> formatted date
echo 'Uptime: ' . $uptime . '. Boottime: ' . $boottime; # yes we have __toString
Uptime will guess your current OS by parsing PHP_OS
constant value. In case you're using any exotic platform that is known to be compatible with one of
the supported systems, you can bypass OS detection by informing
your system identifier manually (case insensitive):
$seconds = uptime('JunOS'); # <float||int> server uptime in seconds
$timestamp = boottime('JunOS'); # <string> server boottime timestamp
You can bypass automatic system detection using the Uptime\System
class too:
use Uptime\System;
$system = new System('JunOS'); # <Uptime\System #>
$system = new System('Amiga'); # throws <Uptime\UnsupportedSystemException #> {}
# patches welcome ;)
shell_exec
function needs to be enabled;PHP_OS
constant value;Uptime\System\SystemTable::$map
;src/Runtime/<NewSystemGroup>/*
, if necessary;test/Runtime/<NewSystemGroup>/*
, if necessary;Copyright (c) 2014-* MΓ‘rcio Almada. Distributed under the terms of an MIT-style license. See LICENSE for details.