简体   繁体   中英

Terminating process running in background using php

I am trying to execute a .exe file using exec() function on my webpage. It sometimes is entering infinite loops and the .exe file is never terminated preventing my php page from proceeding further.

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

Can any one help me out in ending the process when it enters infinite loop?

And i am using XAMPP running on Windows 10

Since CodeFile.exe is a program under your control, I would focus on fixing that first. With rare exceptions, infinite loops do not represent intended or desired behavior. Looking for a timeout option is the equivalent of "sweeping the problem under the rug."

Clearly, CodeFile.exe is an important step in the process, otherwise you wouldn't have written it and made it part of your architecture. Your intention is that it complete before moving on with any subsequent processing. So if it occasionally runs off and never finishes, how can you continue from a broken and unknown state?

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

This worked for me.:) Thank you @Charlie Hills and @FirstOne for your suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM