www.webdeveloper.com
Results 1 to 5 of 5

Thread: Restart PHP File

  1. #1
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287

    Restart PHP File

    I have a php file run from command line, when it finishes a loop, it does a sql query, if there is anything new in the database that was added durring the time it was doing the previous sql query and loop, i would like to have the php file start over, otherwise exit, and close.

    how would I do that?

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    You could use a DO..WHILE loop, with a pseudo condition at the end.
    This would ensure that you perform at least one iteration and as many as needed until you explicitly leave the loop via "break".

    PHP Code:
    <?php
    DO {
      
    $qry mysql_query("SELECT `newitem` FROM `mytable`");
      IF (
    mysql_num_rows($qry) == 0) :
        break;
      ENDIF;
      ....
      ....
      ....
    } WHILE 
    true;
    ?>

  3. #3
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    Your could also re-execute the script using exec() for example.

    But NightShifts idea is much better.

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    I think that the problem with exec() would be that, if this is a very active table with loads of new records added between queries, exec()'s would be calling themselves from within an exec() and the shell stack could end up breaking.

    To go the way of exec() would probably require two scripts, one acting as the control instance and the other as the nested scripts.

  5. #5
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    I am giving your idea a try, it works.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles