PHPackages                             rootiteam/snooze - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rootiteam/snooze

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rootiteam/snooze
================

Thread notification management library for code using the pthreads extension

0.4.2(3y ago)069LGPL-3.0PHP

Since Jul 3Pushed 3y agoCompare

[ Source](https://github.com/RootiTeam/Snooze)[ Packagist](https://packagist.org/packages/rootiteam/snooze)[ RSS](/packages/rootiteam-snooze/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Snooze
======

[](#snooze)

Event-driven thread notification management library for code using the pthreads extension

Use cases
---------

[](#use-cases)

ext-pthreads currently doesn't make it conveniently possible to `wait()` for notifications from multiple threads simultaneously. This library allows you to do that using a `SleeperHandler`.

Every thread must receive its own `SleeperNotifier` (since they are thread-safe, you can share notifiers between threads, but it's recommended not to). The thread should call `wakeupSleeper()` on its `SleeperNotifier`, which will cause the thread waiting on `SleeperHandler` to wake up and process whatever notification was delivered.

It's similar to using the `select()` system call on an array of sockets or file descriptors, but with threads instead.

Example
-------

[](#example)

```
class SleepyThread extends \Thread{
	/** @var \pocketmine\snooze\SleeperNotifier */
	private $notifier;
	/** @var \Threaded */
	private $buffer;

	public function __construct(\pocketmine\snooze\SleeperNotifier $notifier, \Threaded $buffer){
		$this->notifier = $notifier;
		$this->buffer = $buffer;
	}

	public function run() : void{
		$stdin = fopen('php://stdin', 'r');
		while(true){
			echo "Type something and press ENTER:\n";
			//do whatever you're doing
			$line = fgets($stdin); //blocks until the user enters something

			//add the line to the buffer
			$this->buffer[] = $line;

			//send a notification to the main thread to tell it that we read a line
			//the parent thread doesn't have to be sleeping to receive this, it'll process it next time it tries to go
			//back to sleep
			//if the parent thread is sleeping, it'll be woken up to process notifications immediately.
			$this->notifier->wakeupSleeper();
		}
	}
}

$sleeper = new \pocketmine\snooze\SleeperHandler();

$notifier = new \pocketmine\snooze\SleeperNotifier();
$buffer = new \Threaded();
$thread = new SleepyThread($notifier, $buffer);
$sleeper->addNotifier($notifier, function() use($buffer) : void{
	//do some things when this notifier sends a notification
	echo "Main thread got line: " . $buffer->shift();
});

//don't start the thread until we add the notifier, otherwise we could get unexpected behaviour (race conditions)
$thread->start();

while(true){
	$start = microtime(true);
	//do some work that you do every tick

	//process any pending notifications, then try to sleep 50ms until the next tick
	//this may wakeup at any time to process received notifications
	//if it wakes up and there is still time left to sleep before the specified time, it will go back to sleep again
	//until that time, guaranteeing a delay of at least this amount
	//if there are notifications waiting when this is called, they'll be processed before going to sleep
	$sleeper->sleepUntil($start + 0.05);
}

while(true){
	//alternatively, if you want to only wait for notifications and not tick:
	//but from the pthreads rulebook, only ever wait FOR something!
	//this will wait indefinitely until something wakes it up, and then return immediately
	$sleeper->sleepUntilNotification();
}
```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 56.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1095d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d7ee3567bdad5a81cdcff2f03f1aef387d849c1e381dacd55b68bbd818922b7?d=identicon)[ddosnik](/maintainers/ddosnik)

---

Top Contributors

[![dktapps](https://avatars.githubusercontent.com/u/14214667?v=4)](https://github.com/dktapps "dktapps (58 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (30 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (12 commits)")[![globalarray](https://avatars.githubusercontent.com/u/95426617?v=4)](https://github.com/globalarray "globalarray (2 commits)")

### Embed Badge

![Health badge](/badges/rootiteam-snooze/health.svg)

```
[![Health](https://phpackages.com/badges/rootiteam-snooze/health.svg)](https://phpackages.com/packages/rootiteam-snooze)
```

###  Alternatives

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k78.3k91](/packages/pocketmine-pocketmine-mp)[godruoyi/php-snowflake

An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).

8652.6M68](/packages/godruoyi-php-snowflake)[bitwasp/bitcoin

PHP Bitcoin library with functions for transactions, signatures, serialization, Random/Deterministic ECDSA keys, blocks, RPC bindings

1.1k539.0k43](/packages/bitwasp-bitcoin)[pocketmine/raklib

A RakNet server implementation written in PHP

101595.3k16](/packages/pocketmine-raklib)[bitwasp/buffertools

Toolbox for working with binary and hex data. Similar to NodeJS Buffer.

65779.0k42](/packages/bitwasp-buffertools)[pocketmine/math

PHP library containing math related code used in PocketMine-MP

44601.8k22](/packages/pocketmine-math)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
