PHPackages                             derywat/php-processes - 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. derywat/php-processes

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

derywat/php-processes
=====================

PHP process management library

0.1.2(5mo ago)0241MITPHP

Since Dec 11Pushed 5mo agoCompare

[ Source](https://github.com/derywat/php-processes)[ Packagist](https://packagist.org/packages/derywat/php-processes)[ RSS](/packages/derywat-php-processes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (1)

PHP process management library
==============================

[](#php-process-management-library)

Library allows to fork existing php process and provide interprocess messaging.

Using ForkManager
=================

[](#using-forkmanager)

Forking new process
-------------------

[](#forking-new-process)

```
use derywat\processes\ForkManager;

$pid = ForkManager::run('uniqueProcessNameOrId',function($socket){
	//new process code...
});
```

Sending exit signal to child process
------------------------------------

[](#sending-exit-signal-to-child-process)

Internal implementation: SIGTERM signal will be send to child process. Signal will be handled automatically by ForkManager.

```
use derywat\processes\ForkManager;

ForkManager::stop('uniqueProcessNameOrId');
```

Reacting to exit signal in child process
----------------------------------------

[](#reacting-to-exit-signal-in-child-process)

Child process can periodically check if exit was requested.

```
use derywat\processes\ForkManager;

$pid = ForkManager::run('uniqueProcessNameOrId',function($socket){
	//new process code...

	if(ForkManager::childShouldExit()){
		//custom pre-exit code
		exit();
	}

});
```

Interprocess messaging
======================

[](#interprocess-messaging)

Sending message
---------------

[](#sending-message)

Any serializable (by using php internal serialize) data can be passed in message.
Messages can be sent both ways - parent -&gt; child and child-&gt;parent.

```
use derywat\processes\ForkManager;

ForkManager::sendMessage($socket,$data);
```

Receiving messages
------------------

[](#receiving-messages)

Queued messages can be read periodically by using processMessages method.
Messages array contains objects of type InterprocessMessageInterface. Messages array is ordered by the time of sending message - oldest messages first.

Process finished message is sent on forked child process end.

```
	$messages = $ForkManager::processMessages();
	if(!empty($messages)){
		foreach($messages as $message){
			//check if process finished
			if($message->isProcessFinished()){
				//this message was sent on process finish
				//handle finished processes here
			} else {
				//message sent by process running at the time of sending message
				$processNameOrId = $message->getName();
				$processPid = $message->getPid();
				$messageData = $message->getData();
				//handle message and its data here
			}
		}
	}
```

Interprocess commands
=====================

[](#interprocess-commands)

Important

added in version 0.1.1

Interprocess commands handling is higher level abstraction for implementing command dispatching and handling in application.

Defining custom application commands
------------------------------------

[](#defining-custom-application-commands)

Define custom command as class implementing CommandMessageInterface.
\_\_tostring method must be implemented, but it may return any string.

Example class of log command.

```
use derywat\processes\commandMessages\CommandMessageInterface;

class CommandMessageLog implements CommandMessageInterface {

	protected $level;
	protected $message;

	public function __construct($level, $message){
		$this->level = $level;
		$this->message = $message;
	}

	public function getLevel() {
		return $this->level;
	}

	public function getMessage() {
		return $this->message;
	}

	//mandatory method
	public function __tostring(){
		$message = $this->getMessage();
		return "command message - log: {$message}";
	}

}
```

Using CommandMessagesDispatcher
-------------------------------

[](#using-commandmessagesdispatcher)

CommandMessagesDispatcher provide single point of commands or commands groups definitions in app.
Implement own dispatcher by extending CommandMessagesDispatcher class.

```
use derywat\processes\commandMessages\CommandMessagesDispatcher;

class MyCommandMessagesDispatcher extends CommandMessagesDispatcher {

	public static function log($socket, $level, $logMessage){
		static::send($socket,new CommandMessageLog($level,$logMessage));
	}

}
```

Dispatch command with dispatcher in process code. Provide socket for sending message.

```
MyCommandMessageDispatcher::log($socket,'info','log message');
```

Using CommandMessagesHandler in application
-------------------------------------------

[](#using-commandmessageshandler-in-application)

CommandMessagesHandler handles commands in application.
Register command class by using class name and providing handling closure.

```
use derywat\processes\commandMessages\CommandMessagesHandler;

$logger = new MyLoggingClass();

$commandMessagesHandler = (new CommandMessagesHandler())
	->registerCommand(
		CommandMessageLog::class,
		function(CommandMessageLog $command) use ($logger):void {
			$level = $command->getLevel();
			$logMessage = $command->getMessage();
			//call logging code here...
			$logger->log($level,$logMessage);
		}
	);
```

Access original interprocess message in handler
-----------------------------------------------

[](#access-original-interprocess-message-in-handler)

Important

added in version 0.1.2

Optional second parameter of type InterprocessMessageInterface may be added to command handling closure for accessing interprocess message data.

```
use derywat\processes\commandMessages\CommandMessagesHandler;

$logger = new MyLoggingClass();

$commandMessagesHandler = (new CommandMessagesHandler())
	->registerCommand(
		CommandMessageLog::class,
		function(CommandMessageLog $command, InterprocessMessageInterface $message) use ($logger):void {
			$level = $command->getLevel();
			$logMessage = $command->getMessage();

			//use message to pass sending process name as log source
			$logSource = $message->getName();

			//call logging code here...
			$logger->log($level,$logMessage,$logSource);
		}
	);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance72

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

3

Last Release

157d ago

### Community

Maintainers

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

---

Top Contributors

[![derywat](https://avatars.githubusercontent.com/u/46571114?v=4)](https://github.com/derywat "derywat (3 commits)")

### Embed Badge

![Health badge](/badges/derywat-php-processes/health.svg)

```
[![Health](https://phpackages.com/badges/derywat-php-processes/health.svg)](https://phpackages.com/packages/derywat-php-processes)
```

PHPackages © 2026

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