Laravel 5

Laravel 5: Checking if the Script is Executing on a Windows Machine With windows_os

Author

John Koster

Published on April 15, 2018

The windows_os helper function can be used to determine if the host server is running a Microsoft Windows® operating system. The function returns either true—if the server is running Windows®—or false—if the server is not running Windows®.

Signature

The signature of the windows_os function is:

1function windows_os();

Example Use

Using this function you can write code like so:

1<?php
2 
3if (windows_os()) {
4 // Windows® specific commands or instructions.
5} else {
6 // Anything that is not Windows®.
7}

instead of code like this:

1<?php
2 
3if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
4 // Windows&reg; specific commands or instructions.
5} else {
6 // Anything that is not Windows&reg;.
7}