Click to See Complete Forum and Search --> : Restart PHP File


The Little Guy
10-02-2007, 06:49 PM
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?

NightShift58
10-02-2007, 10:49 PM
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
DO {
$qry = mysql_query("SELECT `newitem` FROM `mytable`");
IF (mysql_num_rows($qry) == 0) :
break;
ENDIF;
....
....
....
} WHILE true;
?>

MrCoder
10-03-2007, 05:33 AM
Your could also re-execute the script using exec() for example.

But NightShifts idea is much better.

NightShift58
10-03-2007, 06:50 AM
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.

The Little Guy
10-03-2007, 11:50 AM
I am giving your idea a try, it works.