PHPackages                             pocketmine/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. pocketmine/snooze

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

pocketmine/snooze
=================

Thread notification management library for code using the pthreads extension

0.5.0(3y ago)20595.1k↓15.2%3[1 issues](https://github.com/pmmp/Snooze/issues)[2 PRs](https://github.com/pmmp/Snooze/pulls)6LGPL-3.0PHPCI passing

Since Jun 13Pushed 4mo ago9 watchersCompare

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

READMEChangelog (6)Dependencies (4)Versions (16)Used By (6)

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 NotifyingThread extends \pmmp\thread\Thread{
	public function __construct(
	    private \pocketmine\snooze\SleeperHandlerEntry $sleeperEntry,
	    private \pmmp\thread\ThreadSafeArray $buffer
	){}

	public function run() : void{
		$stdin = fopen('php://stdin', 'r');
		$notifer = $this->sleeperEntry->createNotifier();
		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.
			$notifer->wakeupSleeper();
		}
	}
}

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

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

$thread = new NotifyingThread($sleeperEntry, $buffer);
$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();
}

$thread->join();
//Unregister the notifier when you're done with it
$sleeper->removeNotifier($sleeperEntry->getNotifierId());
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance51

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 60.2% 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 ~164 days

Recently: every ~177 days

Total

12

Last Release

1137d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8a755241617f6c78b33788a288ea7387a417410109293e3a9e3caad74720a44?d=identicon)[dktapps](/maintainers/dktapps)

![](https://www.gravatar.com/avatar/f43e76a228e4a42f099a6ac3c1dbfeadf5e94eaa77e2a70c1431fb12e753255b?d=identicon)[pmmp](/maintainers/pmmp)

---

Top Contributors

[![dktapps](https://avatars.githubusercontent.com/u/14214667?v=4)](https://github.com/dktapps "dktapps (65 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] (13 commits)")

---

Tags

github-actions-enabledon-packagistphp8php81php82php83php84phpstan-l9phpstan-strict

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/pocketmine-snooze/health.svg)](https://phpackages.com/packages/pocketmine-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)
