dtmm0148603 2018-02-13 06:22
浏览 403

设置从远程aws s3文件读取SplFileObject的超时

I am reading a file line by line directly from aws s3 server using SplFileObject.

$url = "s3://{$bucketName}/{$fileName}";
$fileHandle = new \SplFileObject($url, 'r');
$fileHandle->setFlags(SplFileObject::READ_AHEAD);

while(!$fileHandle->eof()){
    $line = $fileHandle->current();
    // process the line        
    $fileHandle->next();
}

That works perfectly fine in 99% of the cases except at times when loop is running and there is a temporary network glitch. Script being unable to access the next line from s3 for x seconds exits prematurely. And the problem is you never know if the script completed its job or it exited due to timeout.

My question here is

1- is there a way to explicitly set timeout on SPLFileObject while accessing remote file so that when the loop exits, I can understand if it exited due to time out or if the file really reached the eof.

I checked the stream_set_blocking and stream_set_timeout but they both do not seem to work with SplFileObject.

2- What is the timeout setting that this script is currently following? is it socket_timeout ? or stream_timeout or curl timeout? or simply php script timeout (which is highly unlikely I guess as the script runs on command line ).

Any hints?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 专家修改了标签 8月18日

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集