简体   繁体   English

如何在Windows的PHP exec()命令上设置超时?

[英]How to setup a timeout on PHP exec() command on Windows?

I am running some php exec commands on PHP - CLI Some of these exec() take too long. 我在PHP-CLI上运行一些php exec命令。这些exec()中的一些花费太长时间。

So my idea is to setup a 60 seconds timeout on the exec() 所以我的想法是在exec()上设置60秒超时

I found some solutions for Linux, but I could not adapt them on windows (pipe/processes...) 我找到了一些适用于Linux的解决方案,但无法在Windows上使用它们(管道/进程...)

Any idea on how to trigger a timeout on windows php cli exec() command ? 关于如何触发Windows php cli exec()命令超时的任何想法吗?

$intExecutionTimeout = 60;
$strCommand = 'wget http://google.com';

$strCommand = 'timeout --signal=15 --kill-after=' . ( $intExecutionTimeout* 2 ) . 's ' . $intExecutionTimeout . 's ' . $strCommand . ' &';

exec( $strCommand, $arrstrResponse );

try timeout command in CLI: 在CLI中尝试timeout命令:

$time = 60;
$command = 'wget http://google.com';
exec(sprintf("C:\Windows\System32\timeout.exe /t %d %s", $time, $command), $output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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