Testing if a server is running with almost no permissions

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

    #1

    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



  • Erwin Moller

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

    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]

    I think you cannot if your provider is so strick.
    I wonder why they are so afraid of file() and fopen().
    Maybe they have something to hide, like the fact that they don't know how to
    set up PHP properly. :-/
    You can always switch provider of course.

    Regards,
    Erwin Moller

    Comment

    • Simon

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

      >[color=blue]
      > I think you cannot if your provider is so strick.
      > I wonder why they are so afraid of file() and fopen().
      > Maybe they have something to hide, like the fact that they don't know how
      > to
      > set up PHP properly. :-/
      > You can always switch provider of course.
      >
      > Regards,
      > Erwin Moller[/color]

      I don't understand?
      file() and fopen() has nothing to do with them, (i think).

      That's just the way php works.

      There must be a way of testing if a domain is "online" or "offline".

      Simon


      Comment

      • Erwin Moller

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

        Simon wrote:
        [color=blue][color=green]
        >>
        >> I think you cannot if your provider is so strick.
        >> I wonder why they are so afraid of file() and fopen().
        >> Maybe they have something to hide, like the fact that they don't know how
        >> to
        >> set up PHP properly. :-/
        >> You can always switch provider of course.
        >>
        >> Regards,
        >> Erwin Moller[/color]
        >
        > I don't understand?
        > file() and fopen() has nothing to do with them, (i think).
        >
        > That's just the way php works.
        >
        > There must be a way of testing if a domain is "online" or "offline".
        >
        > Simon[/color]

        Probably it is me who doesn't understand. :P

        In your original post you wrote this:
        ------------------------------
        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
        ------------------------------

        So I thought your provider was blocking that functionality.

        But You probably mean that they are working, but you cannot use the timeout
        on them? right?

        Nevermind, I am always slow on workingdays. :P

        And sorry: If that is your problem, I don't know the answer.

        However the manual says this:


        ----------------------------------------------
        Note: If you need to set a timeout for reading/writing data over the
        socket, use stream_set_time out(), as the timeout parameter to fsockopen()
        only applies while connecting the socket.
        -----------------------------------------------

        Does that help?


        Regards,
        Erwin Moller

        Comment

        • Chung Leong

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

          Erwin Moller wrote:[color=blue]
          > Simon wrote:
          >[color=green]
          > > 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]
          >
          > I think you cannot if your provider is so strick.
          > I wonder why they are so afraid of file() and fopen().
          > Maybe they have something to hide, like the fact that they don't know how to
          > set up PHP properly. :-/
          > You can always switch provider of course.
          >
          > Regards,
          > Erwin Moller[/color]

          The problem isn't file() or fopen(), but include() and require().
          Remote inclusion is the typical way a PHP worm deploys its payload.
          Currently the only way to disable that is allow_url_fopen , which of
          course disables everything. The good news is that a separate option
          will be added sometime in the future and it'll be off by default.

          Comment

          • Simon

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

            >[color=blue]
            > The problem isn't file() or fopen(), but include() and require().
            > Remote inclusion is the typical way a PHP worm deploys its payload.
            > Currently the only way to disable that is allow_url_fopen , which of
            > course disables everything. The good news is that a separate option
            > will be added sometime in the future and it'll be off by default.[/color]

            No, it has nothing to do with include() or require().
            They are not even used for the same thing.

            The problem is that I am trying to use fopen(...) or file(...) to read the
            content of another site but if that site is down then they simply don't
            return.

            I want a way, (other than system(...) and shell_execute(. ..)), to test if a
            domain is up.

            Simon


            Comment

            • Simon

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

              [color=blue]
              >
              > So I thought your provider was blocking that functionality.
              >
              > But You probably mean that they are working, but you cannot use the
              > timeout
              > on them? right?[/color]

              Right,
              [color=blue]
              >
              > Nevermind, I am always slow on workingdays. :P
              >
              > And sorry: If that is your problem, I don't know the answer.
              >
              > However the manual says this:
              >
              > http://nl3.php.net/manual/en/function.fsockopen.php
              > ----------------------------------------------
              > Note: If you need to set a timeout for reading/writing data over the
              > socket, use stream_set_time out(), as the timeout parameter to fsockopen()
              > only applies while connecting the socket.
              > -----------------------------------------------
              >
              > Does that help?[/color]

              Thanks a lot, you were right.

              My fsockopen(...) was returning ok even if there was no connection

              but adding stream_set_time out($fp, 2); did the trick.

              Thanks.
              [color=blue]
              >
              >
              > Regards,
              > Erwin Moller[/color]

              Simon


              Comment

              • Colin McKinnon

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

                Simon wrote:
                [color=blue][color=green]
                >>
                >> The problem isn't file() or fopen(), but include() and require().[/color]
                >
                > No, it has nothing to do with include() or require().
                > They are not even used for the same thing.
                >[/color]

                Yes it does - they all use the same underlying code for reading files.

                The best solution would be to use curl lib fns in PHP (you can set a
                timeout).
                [color=blue]
                > The problem is that I am trying to use fopen(...) or file(...) to read the
                > content of another site but if that site is down then they simply don't
                > return.
                >[/color]

                So decouple this process from the process which presents the results. Spawn
                it off in the back ground and set it to communicate with the reporting
                process (e.g. by dropping a copy of the data on the local filesystem) when
                succesful
                [color=blue]
                > I want a way, (other than system(...) and shell_execute(. ..)), to test if
                > a domain is up.
                >[/color]

                A domain? Are you sure that is what you mean?

                C.

                Comment

                Working...