Checking connection to a server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clivethebadger
    New Member
    • Feb 2008
    • 12

    Checking connection to a server

    Hi,
    Is it possible to test whether a given URL is reachable within using any server-side scripting?
    Cheers,
    Jon
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    Originally posted by clivethebadger
    Hi,
    Is it possible to test whether a given URL is reachable within using any server-side scripting?
    Cheers,
    Jon
    1. synchronous ajaxing the url. a head request is the quickest.

    2. use the domainOK function below to simply check on rules, not existence.

    Code:
    function qualifyPath(paf) { var i = new Image; i.src = paf; return i.src; }
    
    function domainOK(paf) { 
    var tlc = window.location;
     var myDomain = tlc.hostname || tlc.host; 
    var paf3 = qualifyPath(paf); 
    var pafDomain = paf3.split(/^https?\:\/\//)[1].split(/\//)[0]; 
    return myDomain == pafDomain; }

    Comment

    • clivethebadger
      New Member
      • Feb 2008
      • 12

      #3
      Btw, my original post should have read:

      Hi,
      Is it possible to test whether a given URL is reachable without using any server-side scripting?
      Cheers,
      Jon

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        The first option suggested by rnd me should work. For an example, see the section titled 'Does a URL exist?' on this page.

        Comment

        • clivethebadger
          New Member
          • Feb 2008
          • 12

          #5
          The servers I need to test are remote and this method only seems to work for local paths.

          Cheers,
          Jon

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by clivethebadger
            The servers I need to test are remote and this method only seems to work for local paths.
            If they're from a different domain, then you will need some server-side code, but you said "without using any server-side scripting" so the answer would be that it's not possible.

            Comment

            • clivethebadger
              New Member
              • Feb 2008
              • 12

              #7
              Ok, thanks.

              What would be easiest method of doing this with minimal server-side scripting?

              Thanks,
              Jon

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Make an http request from your server-side script. All it has to return (print/echo) is 0 or 1 (or true/false). Then the Ajax script can check the response.

                Comment

                Working...