简体   繁体   中英

php continue repeat foreach when last element

I have code to bring live ts files for client

I have folder that include dynamic files

/files
1_0.ts
1_1.ts
1_2.ts

My code brings files to client with that code

$files = "";
    $files = glob('/files/1_*.ts');
    foreach ($files as $file) {
    readfile($file);
}

Code get all files and send them to client and everything is ok

I need that client continue read files again when arrive to last element every time until he close browser

more explain

client get
1_0.ts
1_1.ts
1_2.ts
and watch them , I need client to read them again when he at the last file
1_0.ts
1_1.ts
1_2.ts

1_0.ts
1_1.ts
1_2.ts

1_0.ts
1_1.ts
1_2.ts

etc ..... until client close by itself

You can use something like:

while (!connection_aborted()) {

    // here goes Your code that reads the files
    foreach (glob('/files/1_*.ts') as $file)
        readfile($file);

    // some waiting may be useful here?
    sleep(1);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM