I am writing a web page in PHP that will provide some useful tools and information related to a Minecraft server.
I am working on a "status indicator", a system to detect if something is wrong with the server. One of the parts of this system is to use shell_exec to check if there is a server application running on the system. I am using preg_match to check if the result of shell_exec indicates that there is a server application running.
The problem is that no matter what I do, preg_match seems to always return false, which indicates that an error has occurred. I can’t find any details about what exactly this error could be.
function get_server_app_status($appName)
{
if (preg_match($appName, shell_exec('ps aux | grep ' . $appName . ' | grep -v grep')) != 0)
{
return true;
}
else
{
return false;
}
}
I have verified that shell_exec returns what I want it to by shoving it into a variable and checking its value with a debugger, as well as checking $appName. Both are strings and have the values I want them to.
I have also checked what preg_match returns the same way and it does return false, not just zero.
I actually tested the return value for NULL.
And this worked perfectly