简体   繁体   中英

Windows Server killing long running PHP process

I have a Windows 2012 Server that runs IIS and SQL Server 2012.

I am trying to run a PHP script from the command prompt. The script takes around 1 hour to run. If I run it straight from the command line like this - c:\\PHP>php.exe "D:\\Web\\phpScript.php" it runs fine. Again it takes around 1 hour to run but it completes fine.

The thing is I need to run it from another PHP page. So this code - exec('start c:\\php\\php.exe "D:\\Web\\phpScript.php"'); in PHP runs the script. 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.

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. 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.

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.

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

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

Then to execute the external file just use include('D:\\Web\\phpScript.php'); in the script.

http://php.net/manual/en/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.

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