使用php终止在后台运行的进程


Terminating process running in background using php

我试图在我的网页上使用exec()函数执行。exe文件。它有时进入无限循环和。exe文件永远不会终止阻止我的php页面继续。

exec('CodeFile.exe 1>temp''OutputFile.txt<temp''InputFile.txt');
unlink('CodeFile.exe');

当进入无限循环时,谁能帮我结束这个过程?

我在Windows 10上使用XAMPP

由于CodeFile.exe是在您的控制下的程序,我将首先集中精力修复它。除了极少数例外,无限循环并不代表预期或期望的行为。寻找一个超时选项相当于"把问题扫到地毯下"。

很明显,CodeFile.exe是这个过程中的一个重要步骤,否则你就不会编写它并使它成为你的体系结构的一部分。您的意图是在进行任何后续处理之前完成它。所以,如果它偶尔跑掉,永远不会结束,你怎么能从一个破碎和未知的状态继续下去呢?

    exec('CodeFile.exe 1>temp''OutputFile.txt<temp''InputFile.txt & timeout /t 10 & taskkill /im CodeFile.exe /f');
    unlink('CodeFile.exe');

这对我很有效:)谢谢你们的建议。