New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sleep(0) is valid #6955
sleep(0) is valid #6955
Conversation
What's the use-case though? Is it to yield CPU to other processes? |
Our use case is a CLI that accepts an optional startup delay, and we do accept Anyway, I think Psalm should align with PHP's behaviour, that complains only for |
We do have this issue too in our codebase. Our default sleep duration is 0 but can be changed. It feels cheap to make a special condition to avoid calling a sleep instruction that will do nothing |
There's a difference between not calling <?php
$s = microtime(true);
$t = $argv[1];
if ($t >= 0) {
sleep($argv[1]);
}
var_dump('elapsed', number_format(microtime(true) - $s, 6)); I get: $ time php qq.php -1
string(7) "elapsed"
string(8) "0.000018"
user=0.14s system=0.05s cpu=19% total=0.980
$ time php qq.php 0
string(7) "elapsed"
string(8) "0.014775"
user=0.16s system=0.03s cpu=20% total=0.929 (LA ~10). So |
Thanks! |
Is it any different than another "no-action" function call? Let's say strtolower on an empty string? |
It is. Quoting
The net effect of that is that the longer the CPU runqueue, the later your process will be waked up, on average. |
Good to know, thanks! |
https://3v4l.org/qknjR