Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking service is running.

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
Is there a way using PHP to check if a service is running on a certain port? For example, can I query port 80 on my local machine to check if the apache webserver is running?

Thanks.

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
>>Is there a way using PHP to check if a service is running on a certain port? For example, can I query port 80 on my local machine to check if the apache webserver is running?


try using the readfile() method, u can pass a http:// link to it, it will return back the HTML(if any) that it gets...

Known is handfull, Unknown is worldfull
 
There are several OS specific ways to do this.
Please provide some more information about what OS you operate under.
 
You could use the system command `ps -C httpd` and process the output.
Another way is just a socket, fsockopen() to localhost and the desired port.
Depending on the PHP version there are other options, e.g. PHP5 has get_headers() which returns all headers from a request.

You must be running this on the command line, right? Otherwise if you are running it through Apache the fact is given that Apache is running.
 
Yes, sorry apache was a bad example. Basically, I want to determin if a number of services are running by querying the relevant port via PHP. For example if I get a response from port 21 then that implies that the FTP service is running.

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
I'd go with the quick `ps -C ftpd` etc. which shows that the service is running.

For more detailed info and monitoring I'd recommend Big Brother: - it's free.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top