douxian9706 2019-05-22 16:27
浏览 73

Linux中的php中显式超时文件读取I / O操作?

I have production script that copies and renames files from one mounted network share to another (both CIFS), and sometimes the copy function hangs indefinitely on read I/O dropping the process into uninterruptible sleep where it can only be killed with SIGKILL. (Thankfully, TASK_KILLABLE, apparently.)

Since operation is blocked at the copy call I can't gracefully handle the I/O failure, nor, more importantly, log it.

$res = copy("/path/to/mount/file.pdf", "/path/to/productionqueue/newfile.pdf");

//This doesn't run because of the process state.
if($res) {
  //Report success to the log.
} else {
  //Report failure to the log.
}

It's an environment, file-specific issue, and manual intervention can fix it, but I need to log the failure so an administrator can be notified about the condition. (Aside: I think it's a lock race condition. I can fix the problem by unmounting and remounting the source share, but reproducing it is a bit of an issue.)

Ideally, I'd like the copy call to timeout after 10 seconds, so I can log the error, but there doesn't seem to be a way in PHP to do that.

What I'm considering is delegating copy or read operations to a subprocess monitored by the timeout command and responding based on the exit codes, but is there a simpler way in a PHP script to handle this sort of scenario?

Everything I've found in my search suggests there's only runtime configuration available for socket/network timeouts, not filesystem calls.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作