Skip to content
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

[5.5] Worker: Allow to set sleep time less than 1 seconds #22246

Merged
merged 3 commits into from
Nov 29, 2017
Merged

[5.5] Worker: Allow to set sleep time less than 1 seconds #22246

merged 3 commits into from
Nov 29, 2017

Conversation

disc
Copy link

@disc disc commented Nov 29, 2017

I'd like to set sleep time for worker less than 1 seconds, but I can't do this because we use sleep().
I suggest we can use usleep() and multiply passed $seconds to * 100000 for backward compatibility.
Now possible to pass 0.5 or 0.01 seconds

@themsaid themsaid changed the title Worker: Allow to set sleep time less than 1 seconds [5.5] Worker: Allow to set sleep time less than 1 seconds Nov 29, 2017
@themsaid
Copy link
Member

@disk if you sleep less than 1 second why sleep at all? Can you explain the scenario where this is useful?

@disc
Copy link
Author

disc commented Nov 29, 2017

@themsaid I've got a lot of queues and i'd like to decrease sleep timeout, but don't disable it.
Small sleep timeout will produce less load than disabled option.

@taylorotwell taylorotwell merged commit 85e4c4d into laravel:5.5 Nov 29, 2017
@vlakoff
Copy link
Contributor

vlakoff commented Nov 30, 2017

Just to point out PHP_INT_MAX is 2147483647 on 32-bit platform, so this change would break with $seconds > 2147 (about 36 minutes).

@disc
Copy link
Author

disc commented Nov 30, 2017

@vlakoff I agree. I'll rewrite this code and will use usleep in case when sleep less than 1 second

@vlakoff
Copy link
Contributor

vlakoff commented Nov 30, 2017

Alternatively, detect if value would be out of range, and when so, fallback to sleep().

@vlakoff
Copy link
Contributor

vlakoff commented Nov 30, 2017

if (PHP_INT_SIZE < 8 && $seconds >= 2147) {
    sleep($seconds);
} else {
    usleep($seconds * 1000000);
}

This way, we reduce precision only when needed, and you can sleep 1.5 seconds :)

@disc
Copy link
Author

disc commented Nov 30, 2017

Fixed in #22255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants