I have an application written in PHP (Not website, an application), that has an infinite loop for its logic until the application shuts down. One issue with it that I've noticed is I get incredibly high CPU usage (Obviously), and I've tried using C++ methods I've done in the past to lower the CPU usage. Not many of them seem to work.
I've tried:
sleep(1);
and:
time_sleep_until(microtime(true)+0.2);
But neither seem to lower utilization.
Any tips?
sleep(1);usually does sort this problem out, although it is a horrible way to do it. A more important point is what does your application actually do? It's best to let your script stick on a blocking function call until it returns data (e.g. a socket read operation) if possible, can you show your code (or at least an outline of it)?