[Solved] How to check in PHP CLI if LSWS is installed

serpent_driver

Well-Known Member
#1
I want to check in PHP CLI if LSWS is used or installed, but in PHP CLI there is no environment variable about SERVER_SOFTWARE available, because in CLI the PHP build-in webserver is running.

Any Ideas?
 

serpent_driver

Well-Known Member
#3
If PHP is executed in PHP CLI environment LSWS is not in use. PHP uses built-in webserver in PHP CLI but in this environment there are not all variables available.

Run php -i or php -m in PHP CLI to verify
 

Jon K

Administrator
Staff member
#5
You cannot see if LSWS is being used via the command line. It will only be used when using a browser with litespeed. When using via the CLI, it just uses the CLI interface no need for LiteSpeed.

If you need to check it via command line you can curl a phpinfo page and check for server_software there.
 

serpent_driver

Well-Known Member
#7
For everybody who needs a solution to check in PHP CLI if LSWS is running.

PHP:
$url = 'https://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec($ch);
$result = curl_exec($ch);
curl_close($ch);

$lcHeaders = [];
$trim_result = rtrim($result);
$lcData = explode("\n", $trim_result);
$lcHeaders['status:'] = $lcData[0];
array_shift($lcData);

foreach ($lcData as $lcPart) {
    $lcMiddle = explode(":", $lcPart, 2);
    if (!isset($lcMiddle[1])) {
        $lcMiddle[1] = null;
    }
    $lcHeaders[trim($lcMiddle[0])] = trim($lcMiddle[1]);
}

if (isset($lcHeaders["Server"]) && $lcHeaders["Server"] == 'LiteSpeed') {
    echo 'LiteSpeed webserver is running';
}
 
Last edited:
Top