Loop execution of an operation, too many cycles, too long execution lead to errors, how to optimize?

  question

The code looks something like this:

    public function test(){
        for ($i=0; $i < 90260; $i++) { 
            $a = findappbyid($i);
            print_r($a);
            print($i);
        }
    }

After checking about 10 data, there will be:
Fatal error: Maximum execution time of 30 seconds exceeded in xxxx

Is there any better way for him to output the results while running (now there are data and the above-mentioned errors all at once after running), instead of causing errors due to too long running time?

What business logic is this? IffindappbyidIf you look up the database, you just don’t like it.