|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-24 16:37 UTC] saniafd93 at gmail dot com
Description:
------------
*PHP version 5.5.19
Short time ago I wrote an app, that uses usleep(1) for reducing CPU usage. I wrote it on my Windows 8.1 machine, and it's worked as suspected: CPU usage was reduced to 0%-1%. After that, I runned it on Ubuntu 14.04, and there was same behavior: 0%-1.5% CPU usage.
All worked nice untill March 2015, when on Ubuntu CPU usage was increased up to 48% (2-core server). I tested that app again, and found that on Windows CPU usage was still 0%-1%.
I tested it in several environments: 2core Windows 8.1, 4core Windows 8.1, 2core Ubuntu 14.04, 4core Ubuntu 14.04.
Test script:
---------------
<?php
// usage below is right for Ubuntu 14.04 machines
// Windows 8.1 machines all the time have 0%-1.5%
while (true) {
usleep(1); // CPU usage: ~48% 2core machine, ~25% 4core machine
usleep(10000); // CPU usage: ~5% 2core machine, ~1% 4core machine
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 13:00:01 2025 UTC |
Same behavior on Ubuntu 20.04 Php 7.4 Hardware: - Synology DS920+ Virtual Machine: - 4 Core 2 GB RAM Default install in VirtualMachineManager (from Synology) OS: - Ubuntu 20.04 (latest updates at comment) - Installed from LegacyServerISO (not LiveISO) as minimum virtual machine Webserver: - Apache 2.4.41 Default install PHP: - 7.4.3 FPM Default install Test: - while(true){usleep(1);} Result: - Cpu @ ~25% Test: - while(true){usleep(1000);} Result: - Cpu @ ~2% Test: - while(true){sleep(1);} Result: - Cpu @ ~1%