Reputation: 77
What is the best way to limit PHP scripts CPU usage from within that script? I am not looking to re-nice the whole PHP system process, but rather keep a PHP script running for longer and adjusting the CPU usage of that script. Basically, it would need to "renice" itself dynamically and specifically to only the script or it would need to slow down the computations / activities it is doing.
Tried proc_nice()
, but could not get PHP to increase CPU usage of other scripts after my script finished. The change in my script affected other subsequent scripts/requests. This is, when used in my script, and after increasing the nice level, the nice value stayed for the PHP process in the system.
Upvotes: 1
Views: 636
Reputation: 16761
You could usleep() at regular intervals in your code. This will delay script execution for a given number of microseconds leaving more time for other processes.
Upvotes: 1