473,597 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check if a certain service is running on the server

Hi.

I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
Oct 22 '08 #1
12 12809
Shadlan schreef:
Hi.

I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
Hi Shadlan,

If you mean by a service a process: yes.
eg for *nix:
exec("ps -aux");

Have a look at the exec-zoo here:
http://nl3.php.net/manual/en/book.exec.php

If you are on W$ machine, you can pass commandline instructions the same
way.

So once you know WHAT you would do on the commandprompt to get an answer
to your question, you can pass that command to one of the exec function
in PHP and get the result.

http://nl3.php.net/manual/en/function.passthru.php

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Oct 22 '08 #2
On Oct 22, 11:34*am, Shadlan <shad...@arjoc. comwrote:
Hi.

I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
I can not tell if you mean 1. some php service(program ) is installed
on your server and if it is enabled, or if 2. some program called for
in a web page is running at the moment to do something required for
the web page.

If you mean 1. there is a very simple php function that will tell you
much about what your php, if installed, will do. A simple one line web
page is all it takes. See how it works on my server at
http://www.cwdjr.net/php/phpInfo.php . All you need to do is to write
a simple .php page that contains "<?php phpinfo(); ?>" (without
quotes) on one line.

If you mean 2., the process program can be written with some value
such as test set to say 0. The very first step in the program for the
process would be to reset test to say 1. The process should end with
setting test back to 0. You can then check if the process is running
or not by examination of the value of test.
Oct 22 '08 #3
On Oct 22, 6:15*pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
On Oct 22, 11:34*am, Shadlan <shad...@arjoc. comwrote:
Hi.
I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?

I can not tell if you mean 1. some php service(program ) is installed
on your server and if it is enabled, or if 2. some program called for
in a web page is running at the moment to do something required for
the web page.

If you mean 1. there is a very simple php function that will tell you
much about what your php, if installed, will do. A simple one line web
page is all it takes. See how it works on my server athttp://www.cwdjr.net/php/phpInfo.php. All you need to do is to write
a simple .php page that contains "<?php phpinfo(); ?>" (without
quotes) on one line.

If you mean 2., the process program can be written with some value
such as test set to say 0. The very first step in the program for the
process would be to reset test to say 1. The process should end with
setting test back to 0. You can then check if the process is running
or not by examination of the value of test.
Unfortunately it's neither.

I have a Windows Box running a Windows Service created by me that
collects data from several industrial machines and stores it in a
database. The same box is running a web page to allow users to run,
stop and check if the service is running.
Oct 23 '08 #4
Shadlan wrote:
On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
>On Oct 22, 11:34 am, Shadlan <shad...@arjoc. comwrote:
>>Hi.
I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
I can not tell if you mean 1. some php service(program ) is installed
on your server and if it is enabled, or if 2. some program called for
in a web page is running at the moment to do something required for
the web page.

If you mean 1. there is a very simple php function that will tell you
much about what your php, if installed, will do. A simple one line web
page is all it takes. See how it works on my server athttp://www.cwdjr.net/php/phpInfo.php. All you need to do is to write
a simple .php page that contains "<?php phpinfo(); ?>" (without
quotes) on one line.

If you mean 2., the process program can be written with some value
such as test set to say 0. The very first step in the program for the
process would be to reset test to say 1. The process should end with
setting test back to 0. You can then check if the process is running
or not by examination of the value of test.

Unfortunately it's neither.

I have a Windows Box running a Windows Service created by me that
collects data from several industrial machines and stores it in a
database. The same box is running a web page to allow users to run,
stop and check if the service is running.
Maybe try:

$shell = `sc query myService`;

I'm not sure which privileges are needed to run this command, if any,
so you might want to research further.

--
Curtis
Oct 23 '08 #5
On Oct 23, 8:51*am, Curtis <dye...@gmail.c omwrote:
Shadlan wrote:
On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
On Oct 22, 11:34 am, Shadlan <shad...@arjoc. comwrote:
>Hi.
I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
I can not tell if you mean 1. some php service(program ) is installed
on your server and if it is enabled, or if 2. some program called for
in a web page is running at the moment to do something required for
the web page.
If you mean 1. there is a very simple php function that will tell you
much about what your php, if installed, will do. A simple one line web
page is all it takes. See how it works on my server athttp://www.cwdjr..net/php/phpInfo.php. All you need to do is to write
a simple .php page that contains "<?php phpinfo(); ?>" (without
quotes) on one line.
If you mean 2., the process program can be written with some value
such as test set to say 0. The very first step in the program for the
process would be to reset test to say 1. The process should end with
setting test back to 0. You can then check if the process is running
or not by examination of the value of test.
Unfortunately it's neither.
I have a Windows Box running a Windows Service created by me that
collects data from several industrial machines and stores it in a
database. The same box is running a web page to allow users to run,
stop and check if the service is running.

Maybe try:

$shell = `sc query myService`;

I'm not sure which privileges are needed to run this command, if any,
so you might want to research further.

--
Curtis
That does show me if the service is running, but how do I process the
response?

SERVICE_NAME: myService
TYPE : 10 WIN32_OWN_PROCE SS
STATE : 1 STOPPED

(NOT_STOPPABLE, NOT_PAUSABLE,IG NORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CO DE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0

Is there a way to use sc just to read the state?
Oct 23 '08 #6
Shadlan wrote:
On Oct 23, 8:51 am, Curtis <dye...@gmail.c omwrote:
>Shadlan wrote:
>>On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdj r.infowrote:
On Oct 22, 11:34 am, Shadlan <shad...@arjoc. comwrote:
Hi.
I need to know if a service is running on my server. Is there any PHP
instructi on that I can use to do this?
I can not tell if you mean 1. some php service(program ) is installed
on your server and if it is enabled, or if 2. some program called for
in a web page is running at the moment to do something required for
the web page.
If you mean 1. there is a very simple php function that will tell you
much about what your php, if installed, will do. A simple one line web
page is all it takes. See how it works on my server athttp://www.cwdjr.net/php/phpInfo.php. All you need to do is to write
a simple .php page that contains "<?php phpinfo(); ?>" (without
quotes) on one line.
If you mean 2., the process program can be written with some value
such as test set to say 0. The very first step in the program for the
process would be to reset test to say 1. The process should end with
setting test back to 0. You can then check if the process is running
or not by examination of the value of test.
Unfortunate ly it's neither.
I have a Windows Box running a Windows Service created by me that
collects data from several industrial machines and stores it in a
database. The same box is running a web page to allow users to run,
stop and check if the service is running.
Maybe try:

$shell = `sc query myService`;

I'm not sure which privileges are needed to run this command, if any,
so you might want to research further.

--
Curtis

That does show me if the service is running, but how do I process the
response?

SERVICE_NAME: myService
TYPE : 10 WIN32_OWN_PROCE SS
STATE : 1 STOPPED

(NOT_STOPPABLE, NOT_PAUSABLE,IG NORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CO DE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0

Is there a way to use sc just to read the state?
Yes, use regex or string manipulation functions to parse out the exact
data you need from the entire response.

For more information on sc, you'll have to ask google, or find an
appropriate Microsoft NG.

--
Curtis
Oct 23 '08 #7
On Oct 22, 5:34*pm, Shadlan <shad...@arjoc. comwrote:
Hi.

I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
If the service accepts incoming connections then you might be able to
use curl to try and connect to the machine on the port associated with
the service in question. If the service doesn't accept connections
then some other approach would be needed. I've not looked closely at
the responses already made but at first glance they look like they
could work.
Oct 23 '08 #8
Gordon wrote:
On Oct 22, 5:34 pm, Shadlan <shad...@arjoc. comwrote:
>Hi.

I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?

If the service accepts incoming connections then you might be able to
use curl to try and connect to the machine on the port associated with
the service in question. If the service doesn't accept connections
then some other approach would be needed. I've not looked closely at
the responses already made but at first glance they look like they
could work.
Seems like fsockopen() would probably be sufficient.

--
Curtis
Oct 23 '08 #9
On Oct 23, 9:43*am, Curtis <dye...@gmail.c omwrote:
Gordon wrote:
On Oct 22, 5:34 pm, Shadlan <shad...@arjoc. comwrote:
Hi.
I need to know if a service is running on my server. Is there any PHP
instruction that I can use to do this?
If the service accepts incoming connections then you might be able to
use curl to try and connect to the machine on the port associated with
the service in question. *If the service doesn't accept connections
then some other approach would be needed. *I've not looked closely at
the responses already made but at first glance they look like they
could work.

Seems like fsockopen() would probably be sufficient.

--
Curtis
Thanks for all your help. It's working now.

Here's the function that checks if a service is running. It doesn't
include any kind of verification.

function isRunning($serv iceName)
{
exec("sc query $serviceName",$ output); //$output is an array
containing all the lines from the instruction
output=implode( $output); //$output is now a string
return (!strpos($outpu t,'STOPPED'));
}
Oct 23 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1654
by: aurora | last post by:
I am looking for a way for reloading updated modules in a long running server. I'm not too concerned about cascaded reload or objects already created. Just need to reload module xxx if the corresponding xxx.py is updated. I found something useful in module.__file__. Would it work if I use it to generate filenames xxx.py xxx.pyc and then compare their mtime? I'm not too sure about the mechanism of generation of .pyc file. Would it be too...
3
3826
by: Andrew Weaver | last post by:
How do you change the port in which CDONTS will look for Microsoft SMTP server? I have Imail running on port 25, and I have SMTP service running on port 26. Any help you can provide me would be excellent. Thanks, -Drew
5
7251
by: Iwan Petrow | last post by:
Hi, I have Win application -> Web service -> Sql Server. The user input date and time in format dd/MM/yy hh:mm. I convert it to datetime and send it to a web service which save it to the db. But the datetime is changed according the timezone of the server and the client machine (I think). What can I do that the date to stay the same (I want to send datetime type and I don't want to change windows setting of the server and the client...
1
1250
by: Stephen Corey | last post by:
I've got a windows service running as NetworkService on a WinXP Pro machine. Is there a way for it to find the Active Directory account of the logged on user? I don't mind switching the service to run as a "Domain Admin" if needed, but I *need* to find out the LDAP path for the user. Thanks!
3
2198
by: jliusolar | last post by:
Hi I am trying to figure out why an application get this error when I am trying to open the application's asmx file from localhost. I don't have indexing service running(it set as manual and not started). I also created an .aspx file to do testing The .aspx file opens fine in other directory from IE. As long as I put it in the application's directory, set a virtual directory trying to open it, it also gives me the following error. I don't...
0
1117
by: Jennyfer J Barco | last post by:
Hello, I have a .NET service running and sometimes, not very often I receive this error "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. General network error. Check your network documentation" I don't know what is causing it. My web server is in one server and my SQL is in a different server. The SQL server has not so many transactions. This service is reading a table every...
0
998
by: Computer geek | last post by:
I am a beginner programmer and would like a little help with a piece of code. Does anyone know how write code that will check the status of a service running on a remote server? Or is it even possible to do such a thing? I'd like to have it make sure that the serice is started.
2
11937
by: Bill Fuller | last post by:
I am trying to attach to a WCF Web Service running in virtual directory in my local dev box, but not sure how to do it. I tried setting a breakpoint on the .svc and attaching to the Inetinfo process, but it doesn't break. I am getting a SQL connection error, but the message is rather vague. The web.config connecton string looks fine.
0
2903
by: Gordon | last post by:
On Oct 23, 9:43 am, Curtis <dye...@gmail.comwrote: if ($handle = fsockopen ('localhost', 80, $errnum, $errmsg, 1)) { echo ('A web server is running on this system<br>'); fclose ($handle); } else { echo ($errnum . ' ' . $errmsg . '<br>');
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.