Testing if a server is running with almost no permissions

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

    Testing if a server is running with almost no permissions

    Hi,

    My webhost allows me to run php but no shell_execute(. ..), system(...) and
    so on.

    I am trying to get info from a site, the reply from the site is usually less
    than 1 second.

    I have tried

    fsockopen("http ://www.example.com ", 80, $errno, $errstr, 1);
    //and
    file( "http://www.example.com ")
    //
    fopen( ..., "r" );

    But that does not work

    according to php.net
    "Depending on the environment, the Unix domain or the optional connect
    timeout may not be available."

    I cannot change "Set_time_limit (...)" because I have no access to the
    php.ini file.

    So, how can i test for a website and have a 1 second timeout?

    Many thanks in advance.

    Simon


  • Steve

    #2
    Re: Testing if a server is running with almost no permissions

    On Thu, 12 Jan 2006 12:56:14 +0000, Simon wrote:
    [color=blue]
    > Hi,
    >
    > My webhost allows me to run php but no shell_execute(. ..), system(...) and
    > so on.
    >
    > I am trying to get info from a site, the reply from the site is usually less
    > than 1 second.
    >
    > I have tried
    >
    > fsockopen("http ://www.example.com ", 80, $errno, $errstr, 1);
    > //and
    > file( "http://www.example.com ")
    > //
    > fopen( ..., "r" );
    >
    > But that does not work
    >
    > according to php.net
    > "Depending on the environment, the Unix domain or the optional connect
    > timeout may not be available."
    >
    > I cannot change "Set_time_limit (...)" because I have no access to the
    > php.ini file.
    >
    > So, how can i test for a website and have a 1 second timeout?
    >
    > Many thanks in advance.
    >
    > Simon[/color]

    Look at adding entries to control php configuration in your .htaccess
    file, and the ini_set()/init_get() functions.

    Steve

    Comment

    • Al

      #3
      Re: Testing if a server is running with almost no permissions

      As for the original question... If your server has cURL support, try
      using that:
      It works like fopen with URLs when that feature is disabled.

      I stole this from a firefox XML feed ticker code but here's the basic
      script:


      <?php

      function getResponse($ur l, $port, $timeout) {
      $ch = curl_init();

      curl_setopt($ch , CURLOPT_URL, $url);
      curl_setopt($ch , CURLOPT_HEADER, 0);
      curl_setopt($ch , CURLOPT_FOLLOWL OCATION, 1);
      curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
      curl_setopt($ch , CURLOPT_FRESH_C ONNECT, 1);
      curl_setopt($ch , CURLOPT_TIMEOUT , $timeout);
      curl_setopt($ch , CURLOPT_PORT, $port);

      $data = curl_exec($ch);
      curl_close($ch) ;

      if ($data === NULL)
      return "Error"; // i assume this where you decide if the
      server's down or whatever you wanted to do

      return $data;
      }

      $infoFromSite = getResponse("ht tp://www.example.com/", 80, 25);

      echo
      "<html><hea d></head><body><pre >".htmlentities ($infoFromSite) ."</pre></body></html>";

      ?>

      Comment

      Working...