简体   繁体   English

后台Windows上的命令行中的PHP Exec PHP脚本

[英]PHP Exec PHP script from command line on Windows in the background

I have a PHP page that I am executing from another PHP page like this - exec('c:\\php\\php.exe processing.php > NUL '); 我有一个PHP页面,我正在从另一个这样的PHP页面exec('c:\\php\\php.exe processing.php > NUL ');

The processing page has a SQL stored procedure that runs and takes awhile to complete after the stored procedure is complete the page then creates a .csv from the results and drops it into a directory. 处理页面上有一个SQL存储过程,该过程将运行并在存储过程完成后花一些时间才能完成,然后从结果中创建一个.csv并将其放入目录中。

This entire process works fine as long as it does not take too long to execute. 只要执行时间不长,整个过程就可以正常工作。 If I am running it on a few thousand records it only takes like 3-5 minutes and completes fine. 如果我在几千条记录上运行它,则只需要3-5分钟即可完成。 If I run it with like 20K records the process takes over 10 minutes to complete but is getting killed before it's done. 如果我以20K的记录运行它,则该过程需要10分钟以上的时间才能完成,但是在完成之前会被杀死。

The speed is not the issue, we are fine with it taking awhile to run but somehow the script is getting killed. 速度不是问题,我们可以花一些时间来运行它,但是脚本以某种方式被杀死了。 While it's running I can see the CLI process from the task manager in Windows but it seems like if it takes more than 10 minutes Windows is killing it or something. 在运行时,我可以从Windows的任务管理器中看到CLI进程,但是好像Windows杀死它或花费了10分钟以上。

I am just trying to figure out how I can run this without the process getting killed for taking too long. 我只是想弄清楚如何才能运行此程序,而不会因为花费太长时间而使进程被杀死。

Any help on this would be greatly appreciated. 任何帮助,将不胜感激。

Thanks! 谢谢!

Try using set_time_limit(0) (see documentation: http://php.net/manual/en/function.set-time-limit.php ). 尝试使用set_time_limit(0) (请参阅文档: http : //php.net/manual/zh/function.set-time-limit.php )。

Setting time limit to 0 will remove any time limit. 将时间限制设置为0将删除任何时间限制。

Also, make sure you're not having any memory issue. 另外,请确保您没有任何内存问题。 If your script tries to allocate too much memory it will be killed anyway. 如果您的脚本尝试分配过多的内存,则无论如何它都会被杀死。 You can check memory usage of your script with memory_get_usage() (see documentation: http://php.net/manual/en/function.memory-get-usage.php ) 您可以使用memory_get_usage()检查脚本的内存使用情况(请参阅文档: http : //php.net/manual/en/function.memory-get-usage.php

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

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