Skip to content
Get information of the current operating system where PHP is running on.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
spec/drupol/phposinfo
src Update to newest drupol/php-conventions. Aug 15, 2019
tests/src/Enum Update to newest drupol/php-conventions. Aug 15, 2019
.editorconfig Initial commit. Jul 4, 2019
.gitattributes
.gitignore Initial commit. Jul 4, 2019
.scrutinizer.yml
.travis.yml
LICENSE
README.md
appveyor.yml
composer.json
grumphp.yml.dist
infection.json.dist Initial commit. Jul 4, 2019
phpspec.yml.dist

README.md

Latest Stable Version GitHub stars Total Downloads Travis AppVeyor CircleCI Scrutinizer code quality Code Coverage Mutation testing badge License Say Thanks! Donate!

PHP OS Info

Description

Get information of the current operating system where PHP is running on.

Information that you can retrieve are:

  • Operating system
  • Operating system family

There are many packages that does that already but most of them are based on the use of the variable PHP_OS that contains the operating system name PHP was built on, from php.net:

 The operating system PHP was built for.

However, PHP_OS might be sometimes not very accurate, then using php_uname() might be a better fit for detecting the operating system, we only use it as a fallback.

This library uses php_uname() and a static list of existing operating systems, and then from there, tries to deduct the operating system family.

From PHP 7.2, the variable PHP_OS_FAMILY was added and based on the definition from php.net:

 The operating system family PHP was built for.
 Either of 'Windows', 'BSD', 'Darwin', 'Solaris', 'Linux' or 'Unknown'. 

So once again, if you're using a PHP which is cross compiled, using those constant is a bad idea.

Requirements

  • PHP >= 5.6

Installation

composer require drupol/phposinfo

Usage

<?php

include 'vendor/autoload.php';

use drupol\phposinfo\OsInfo;
use drupol\phposinfo\Enum\Family;
use drupol\phposinfo\Enum\Os;

// Register constants if they do not exists:
// * PHP_OS_FAMILY
// * PHP_OS
// * PHPOSINFO_OS_FAMILY
// * PHPOSINFO_OS
OsInfo::register();

// Get the OS name.
OsInfo::os();

// Get the OS family.
OsInfo::family();

// Check if the OS is Unix based.
OsInfo::isUnix();

// Check if the OS is Apple based.
OsInfo::isApple();

// Check if the OS is Windows based.
OsInfo::isWindows();

// Check the OS version.
OsInfo::version();

// Check the OS release.
OsInfo::release();

// Check if the OS Family is Family::UNIX_ON_WINDOWS.
OsInfo::isFamily(Family::UNIX_ON_WINDOWS);

// Check if the OS is Os::FREEBSD.
OsInfo::isOs(Os::FREEBSD);

// Check if the OS is Windows.
OsInfo::isOs('windows');

// Check if the OS family is darwin.
OsInfo::isFamily('darwin');

Code quality, tests and benchmarks

Every time changes are introduced into the library, the continuous integration bots run the tests.

Current CI services are:

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to check manually.

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)

You can’t perform that action at this time.