PHP - win32_query_service_status

Associate
Joined
1 May 2006
Posts
810
Location
Bristol, UK
Afternoon all.

Not sure how many people have had experience with this function but the various PHP sites don't have many comments!
I'm trying to query the status of the various services i.e. apache.exe, filezilla-server.exe etc and output either "Running" or "Stopped" for each one.
Here's what I have so far:
Code:
if(win32_query_service_status("apache")="FALSE")
	{
	$webserver_status = "<font color=FF0000>Stopped</font>";
	}
else
	{
	$webserver_status = "<font color=00FF00>Running</font>";
	}
But I get the error:
Code:
Fatal error: Can't use function return value in write context
When I just try executing win32_query_service_status("apache"); I get:
Code:
Fatal error: Call to undefined function win32_query_service_status()

Any suggestions as to how I can get this to work? Or any other functions that will do a better job?
Cheers.
 
Have you got the service name correct? It will be the actual service name not the name of the executable.
 
Ok, the first error message is because you're using '=' and not '=='. The first line should read...

Code:
if ( win32_query_service_status("apache") == false )


The second error probably means you haven't installed the win32 service extension. Download the appropriate version from here:

http://pecl4win.php.net/ext.php/php_win32service.dll

Place the DLL in the 'ext' directory and include it in the php.ini file.

Hope this helps.
 
P.J. Thanks for that. I had the php_win32service.dll file in the ext folder but it wasn't enabled in php.ini
I've since enabled it and rebooted my server but to no avail, I'm still getting the undefined function error :(
 
Last edited:
Code:
<?php
$test = win32_query_service_status('apache');
if ($test['CurrentState'] == 1){
    $webserver_status = "<font color=FF0000>Stopped</font>";
}
if ($test['CurrentState'] == 4){
    $webserver_status = "<font color=00FF00>Running</font>";
}
echo $webserver_status;
?>

try that? :)
 
Thanks for the contribution marc. TBH your code will work better for me IMO.
I still get the undefined function error though. I've even gone back to the php.net site and followed the installation instructions for php_win32service.dll and still no joy.
Does it matter that I'm running XAMPP? Is there anything in the php.ini (or anywhere else) that could be conflicting with it?
 
Naffing XAMPP has php.ini's all over the place. I went to the most logical one (in the php folder). Nope, it was in apache\bin :confused:

Everything works now!

The lesson: Always read the instruction manual! :p

Thanks for your input guys.
 
Back
Top Bottom