proc_nice()
on Windows
Modern operating systems, as we all know, support the concurrent execution of different programs. Technically, an operating system runs multiple processes (that can each run in multiple threads, but that is not the point here). Since there are typically more processes than CPU cores, the operating system needs to make sure that each CPU core takes turns in working on the different processes it runs. This is called scheduling.
By assigning a priority to each process, we can make sure that important processes get more CPU time. If you build an index of all the files in your file system, and watch a video at the same time, you do not want your video to become jerky. The solution is to give the video rendering process a higher priority than the indexing process.
Unix/Linux users might be familiar with nice
, a *NIX
system tool that can modify the priority of a running process. In
PHP, you can use the function proc_nice()
to change the
priority of the process that runs your currently executed PHP
script. Remember that positive values will lower the priority of
your process – after all, the whole point should not be to get more
CPU, but to be nice to the other users of a system.
As of PHP 7.2, the function proc_nice()
is also
available on Windows. In recent years, Microsoft has put effort into
making sure that all PHP features that are available on *NIX,
especially Linux, are also made available on Windows.
proc_nice()
is probably one of the last functions that
previously was not supported on Windows.