Elektrine lite

← Feed

@flowcontrol@phpc.social

Post #572185

2026-02-17 19:36 UTC

#PHP poll: is `sleep(5)` guaranteed to sleep at least 5 seconds?

Replies (6)

  • @bobmagicii@phpc.social 2026-02-17 21:57

    @flowcontrol@phpc.social to this day i still have that initial sense of wonder the first time i accidentally observed it

    Open ##2438950

  • @bryanredeagle@beige.party 2026-02-17 22:47

    @flowcontrol@phpc.social I never trust anything time based. It's all just pretty close enough in my book.

    Open ##2438951

  • @edorian@phpc.social 2026-02-18 01:47

    @flowcontrol@phpc.social my assumption is that it is just a sleep(3) wrapper and works like it

    Open ##2438952

  • @jaapio@phpc.social 2026-02-18 05:20

    @flowcontrol@phpc.social sleep is always fuzzy. Depending on the implementation it can be very strange. Especially with low numbers, and developers trying to be smart to make the sleep more precise.

    Open ##2438953

  • @dseguy@phpc.social 2026-02-18 09:53

    @flowcontrol@phpc.social I suspect sleep() relies on the internal clock, which might be changed at any moment. But I have never observed it. I think hrtime() works better for that, and is system immune. All in all, this looks like something going to the php-tips archive :)

    Open ##2438954

  • @paranoiq@witter.cz 2026-02-18 15:17

    @flowcontrol@phpc.social sleap() returns earlier, if interrupted with a signal. you need to handle signals and call sleap again with the rest of planned sleap interval

    Open ##2438956