PHP继续重复foreach当最后一个元素 [英] php continue repeat foreach when last element

查看:102
本文介绍了PHP继续重复foreach当最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码为客户端带来实时ts文件

我有包含动态文件的文件夹

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

我的代码通过该代码将文件带到客户端中

  $ files =; 
$ files = glob('/ files / 1 _ *。ts');
foreach($ files为$ file){
readfile($ 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 ... 。直到客户端自己关闭


解决方案



  while(!connection_aborted()){

// here here您的代码读取文件
foreach(glob('/ files / 1 _ *。ts')as $ file)
readfile($ file);

//一些等待在这里可能有用吗?
sleep(1);
}


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);
}

这篇关于PHP继续重复foreach当最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆