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

我有生产脚本,将文件从一个已安装的网络共享复制并重命名为另一个(均为CIFS),有时还有 copy </ code>函数在读取I / O上无限期挂起,将进程放入不间断的睡眠状态,只能使用 SIGKILL杀死它。</ code>(谢天谢地,显然是TASK_KILLABLE。)</ p>

由于操作在 copy </ code>调用时被阻止,我无法正常处理I / O故障,更重要的是,无法记录它。</ p>

  $ res = copy(“/ path / to / mount / file.pdf”,“/ path / to / productionqueue / newfile.pdf”); 
nn //这不会运行,因为 进程状态。
if($ res){
} else {
</ code> </ pre>

这是一个环境,特定于文件的问题,手动干预可以修复它,但我需要记录失败,以便管理员可以收到有关该情况的通知。 (旁白:我认为这是一个锁定竞争条件。我可以通过卸载和重新安装源共享来解决问题,但重现它有点问题。)</ p>

理想情况下,我 d喜欢 copy </ code>在10秒后调用超时,所以我可以记录错误,但是在PHP中似乎没有办法做到这一点。</ p>

< p>我正在考虑的是将复制或读取操作委托给由 timeout </ code>命令监视的子进程并根据退出代码进行响应,但在PHP脚本中有一种更简单的方法来处理这种排序 方案?</ p>

我在搜索中发现的一切都表明,只有运行时配置可用于套接字/网络超时,而不是文件系统调用。 </ p>
</ div>



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.

Csdn user default icon