Automated Script

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

    #1

    Automated Script

    Guys, I need to make an automated script that runs every x seconds
    without using a CRON job.

    I heard there was a way doing it only in PHP. If you know any function
    that can be used please inform me about it.

  • chotiwallah

    #2
    Re: Automated Script

    not possible using php only.

    three possible ways around:

    1. use some web based cron (can't remember an url at the moment, sorry)

    2. if you have a local pc that's online 24h, have a little program
    there calling the automated script every x seconds

    3. use the most frequented page of your website to call the automated
    script (using a blind image, for instance). you'd have to include a
    timer in the automated script than.

    micha

    Comment

    • Andrew @ Rockface

      #3
      Re: Automated Script

      chotiwallah wrote:[color=blue]
      > not possible using php only.
      >
      > three possible ways around:
      >
      > 1. use some web based cron (can't remember an url at the moment, sorry)
      >
      > 2. if you have a local pc that's online 24h, have a little program
      > there calling the automated script every x seconds
      >
      > 3. use the most frequented page of your website to call the automated
      > script (using a blind image, for instance). you'd have to include a
      > timer in the automated script than.[/color]

      You could use an infinite loop and stick the code to be executed inside
      with a sleep at the end.

      $x = 5;
      while(1) {
      echo "Hello world";
      sleep($x);
      }

      Or if you want to re-execute the code a set number of times use:

      $x = 5;
      $y = 10;
      for ($c = 0; $c < $y; $c++) {
      echo "Hello world";
      sleep(5);
      }

      --
      Andrew @ Rockface
      np: Sylvie - Smoke and Mirrors [stopped]

      Comment

      • Adam

        #4
        Re: Automated Script

        On Tue, 4 Oct 2005 07:50:59 +0000 (UTC), Andrew @ Rockface wrote:
        [color=blue]
        >chotiwallah wrote:[/color]
        [color=blue]
        >You could use an infinite loop and stick the code to be executed inside
        >with a sleep at the end.
        >
        >$x = 5;
        >while(1) {
        > echo "Hello world";
        > sleep($x);
        >}[/color]

        I've been digging around looking for info on precisely this topic.

        Not sure whether your code will work (infinitely). It will simply hit
        the maximum page execution time set by php.ini on the server - then
        throw an ugly error.

        You could extend that time with ini_set() - but I'm not sure whether
        there's a memory or performance hit on a server processing an infinite
        loop. It would also dependon what is actually happeniong iside the
        loop.

        Adam.

        Comment

        • Andrew @ Rockface

          #5
          Re: Automated Script

          Adam wrote:[color=blue]
          > On Tue, 4 Oct 2005 07:50:59 +0000 (UTC), Andrew @ Rockface wrote:
          >
          >[color=green]
          >>chotiwallah wrote:[/color]
          >
          >[color=green]
          >>You could use an infinite loop and stick the code to be executed inside
          >>with a sleep at the end.
          >>
          >>$x = 5;
          >>while(1) {
          >> echo "Hello world";
          >> sleep($x);
          >>}[/color]
          >
          >
          > I've been digging around looking for info on precisely this topic.
          >
          > Not sure whether your code will work (infinitely). It will simply hit
          > the maximum page execution time set by php.ini on the server - then
          > throw an ugly error.
          >
          > You could extend that time with ini_set() - but I'm not sure whether
          > there's a memory or performance hit on a server processing an infinite
          > loop. It would also dependon what is actually happeniong iside the
          > loop.[/color]

          True.

          I generally run php scripts using wget from a crontab job. In fact I do
          that every hour to run remote tests on around 60 sites and have found
          it's perfect for the job.

          --
          Andrew @ Rockface
          np: (Winamp is not active ;-)

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: Automated Script

            chotiwallah wrote:[color=blue]
            > not possible using php only.
            >
            > three possible ways around:
            >
            > 1. use some web based cron (can't remember an url at the moment, sorry)[/color]

            FWIW, it's webcron.com

            <snip>
            [color=blue]
            > 3. use the most frequented page of your website to call the automated
            > script (using a blind image, for instance)[/color]

            FWIW, you don't have to go for webbug, it's enough that you put your
            own cron_handler() function in frequently accessed PHP file. May also
            use auto_prepend_fi le feature
            <http://in2.php.net/ini.core#ini.au to-prepend-file>, (but it's a
            discouraged approach). But, as you said, it's like reinventing the
            wheel.

            Possibly, the pure PHP solution is to use sleep() function and set
            the maximum execution time to 0 (no limit) and to use it in command
            line (so, that it doesn't use webserver resources).

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            Working...