Checking port status using php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asdf

    Checking port status using php

    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.

    thanks
  • C. (http://symcbean.blogspot.com/)

    #2
    Re: Checking port status using php

    On 3 Nov, 23:38, asdf <a...@asdf.comw rote:
    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.
    >
    thanks
    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.

    C.

    Comment

    Working...