简体   繁体   中英

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 ');

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.

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. If I run it with like 20K records the process takes over 10 minutes to complete but is getting killed before it's done.

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.

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

Setting time limit to 0 will remove any time limit.

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 )

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