简体   繁体   English

Windows Server杀死了长期运行的PHP进程

[英]Windows Server killing long running PHP process

I have a Windows 2012 Server that runs IIS and SQL Server 2012. 我有一个运行IIS和SQL Server 2012的Windows 2012 Server。

I am trying to run a PHP script from the command prompt. 我正在尝试从命令提示符下运行PHP脚本。 The script takes around 1 hour to run. 该脚本大约需要1个小时才能运行。 If I run it straight from the command line like this - c:\\PHP>php.exe "D:\\Web\\phpScript.php" it runs fine. 如果我从这样的命令行直接运行它-c:\\ PHP> php.exe“ D:\\ Web \\ phpScript.php”,它将正常运行。 Again it takes around 1 hour to run but it completes fine. 再次需要大约1个小时来运行,但是可以正常运行。

The thing is I need to run it from another PHP page. 问题是我需要从另一个PHP页面运行它。 So this code - exec('start c:\\php\\php.exe "D:\\Web\\phpScript.php"'); 所以这段代码-exec('start c:\\ php \\ php.exe“ D:\\ Web \\ phpScript.php”'); in PHP runs the script. 在PHP中运行脚本。 When I run it from PHP like that it runs good for around 30 minutes or so but for some reason Windows ends up killing the process after around 30 minutes. 当我从PHP像这样运行时,它可以在30分钟左右的时间内运行良好,但是由于某种原因,Windows大约在30分钟后终止了该进程。

I have been watching the task manager on Windows and cannot see any difference in the way the process runs compared to when I run it straight from the command prompt or when I use PHP to run the command. 我一直在观察Windows上的任务管理器,与直接从命令提示符下运行它或使用PHP运行命令时相比,看不到进程运行方式的任何差异。 They both show up as a background process and look exactly the same in the task manager but for some reason Windows is killing the one that runs from PHP and not the one ran straight from the command prompt. 它们都显示为后台进程,并且在任务管理器中看起来完全相同,但是由于某些原因,Windows正在杀死从PHP运行的进程,而不是直接从命令提示符运行的进程。

I have even tried running the PHP one in Realtime thinking maybe if it had higher priority it would not get killed but that did not help. 我什至尝试以实时方式运行PHP之一,也许如果它具有更高的优先级,它不会被杀死,但这没有帮助。

I am really stuck with this. 我真的很坚持这一点。

Any help would be great. 任何帮助都会很棒。

Thanks! 谢谢!

If it has to do with your PHP configuration, you can force allowing a certain execution time with this at the beginning of the script 如果它与您的PHP配置有关,则可以在脚本开始时强制使用此时间来允许一定的执行时间

set_time_limit(60*60*2); // allows 2 hours execution time

Then to execute the external file just use include('D:\\Web\\phpScript.php'); 然后要执行外部文件,只需使用include('D:\\Web\\phpScript.php'); in the script. 在脚本中。

http://php.net/manual/en/function.set-time-limit.php http://php.net/manual/zh/function.set-time-limit.php

Otherwise if its a server problem, beats me. 否则,如果它是服务器问题,就会打败我。 You could, of course...run it in your web browser instead of in the command prompt, if PHP is installed on the machine. 如果计算机上已安装PHP,则当然可以在Web浏览器中而不是在命令提示符下运行它。

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

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