Checking port status using php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm using ssh2_connect to execute a certain command on a group of servers.
The problem is that not all of them are necessarily on the network which
causes php script to execute for extended periods of time. Is there a way
to either specify a timeout on a command such as ssh_connect or
alternatively is there a command to check if a certain port (22 in my
case) is accepting connections. Then it's a simple matter of using if then
to execute the rest of the program.


Re: Checking port status using php

Quoted text here. Click to load it

You're trying to solve the wrong problem in the wrong way here.

First, there are lots of existing tools for managing clusters (Ubuntu
Landscape springs to mind - but there are many, many more). Why write
your own.

If the problem is the length of time for the connection, then testing
the port before connecting is going to be just as expensive.

Why are you trying to do this in a single thread - a better solution
would be to start seperate threads of execution for each job and have
them report back to a central location. How do I run long-running
processes in PHP is a FAQ - try Google.

You also have to think about how you deal with errors - extending the
approach above, a better solution would be to use an asynchronous
message queue to despatch the jobs to servers.


Site Timeline