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? 12 12755
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
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.
On Oct 22, 6:15*pm, cwdjrxyz <spamtr...@cwdjr.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.
Shadlan wrote:
On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdjr.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
On Oct 23, 8:51*am, Curtis <dye...@gmail.comwrote:
Shadlan wrote:
On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdjr.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_PROCESS
STATE : 1 STOPPED
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
Is there a way to use sc just to read the state?
Shadlan wrote:
On Oct 23, 8:51 am, Curtis <dye...@gmail.comwrote:
>Shadlan wrote:
>>On Oct 22, 6:15 pm, cwdjrxyz <spamtr...@cwdjr.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_PROCESS
STATE : 1 STOPPED
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 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
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.
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
On Oct 23, 9:43*am, Curtis <dye...@gmail.comwrote:
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($serviceName)
{
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($output,'STOPPED'));
}
Shadlan wrote:
On Oct 23, 9:43 am, Curtis <dye...@gmail.comwrote:
>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($serviceName)
{
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($output,'STOPPED'));
}
Glad to hear it's working; nice solution. :-)
--
Curtis
On Oct 23, 9:43*am, Curtis <dye...@gmail.comwrote:
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
Yeah, good point. That just occurred to me a couple of minutes after
making the post.
Shadlan wrote:
On Oct 23, 9:43 am, Curtis <dye...@gmail.comwrote:
>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($serviceName)
{
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($output,'STOPPED'));
}
I just realized a couple improvements:
1.) strpos() will not work if "STOPPED" were to start on index 0. You
should test against FALSE with ===. Easier would be to use
strstr() or stristr() for case insensitivity.
2.) You can eliminate the need for imploding if you use the execution
operator (``). You can also simply store the return value of
exec(), like below.
function isRunning($serviceName)
{
$output = exec("sc query $serviceName");
// the same thing:
// $output = `sc query $serviceName`;
return !stristr($output, 'STOPPED');
}
--
Curtis
$eMail = str_replace('sig.invalid', 'gmail.com', $from); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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);
}...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |