Giter VIP home page Giter VIP logo

uptime's Introduction

Uptime - PHP

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads 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.

Supported Platforms

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 ?

Composer Installation

{
  "require": {
    "uptime/uptime": "~0.1"
  }
}

Through terminal: composer require uptime/uptime:~0.1 🎱

Quick Guide

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

$bootime = $system->getBootime(); # <Uptime\Bootime implements \DateTime #> {}
$bootime->format('Ymd H:i:s');    # <string> formatted date

echo 'Uptime: ' . $uptime . '. Boottime: ' . $bootime; # 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 ;)

Notes

  • Returned values will be as precise as your platform allows to, usually microseconds but it can be seconds;
  • Some platforms need a better way to get uptime and boottime;
  • For some platforms shell_exec function needs to be enabled;

Extending Platform Support

  1. Check PHP_OS constant value;
  2. Map your platform or system identifier on Uptime\System\SystemTable::$map;
  3. Create a new runtime under src/Runtime/<NewSystemGroup>/*, if necessary;
  4. Add new tests to test/Runtime/<NewSystemGroup>/*, if necessary;
  5. Pull request;

Features & Roadmap

  • Functional API
  • OO API
  • Add a facade
  • Write guide and manual
  • Better cross platform tests
  • Try to avoid child processes
  • Maybe C extension

Copyright

Copyright (c) 2014 Márcio Almada. Distributed under the terms of an MIT-style license. See LICENSE for details.

uptime's People

Contributors

marcioalmada avatar

Watchers

Átila Camurça Alves avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.