I have some long-running CLI PHP scripts that run regularly via cron. I'd like them to complete as quickly as possible but without seriously impacting other processes (such as web server responsiveness).
Currently I am running the script with
nice -n 19
and also have experimented with inserting very short usleep() calls, such as 50 microseconds in my main loop. Still this isn't always yielding as quickly as I'd like on a single-core VM. BTW, I'm not saturating RAM so there's no paging happening.
I've read that usleep() is a system call that will allow the scheduler to assign priority to other processes if needed more quickly than if I didn't have any system calls.
What I'm wondering is if there's a better method of doing this in PHP. Such as a call that doesn't sleep but yields priority right away.
Also, I know other languages are more efficient than PHP, but this is part of a bigger app written in Symfony+Doctrine. I don't want to split into multiple languages and lose the business logic benefits of the app's models.