PHP code example of ssigwart / process-pool

1. Go to this page and download the library: Download ssigwart/process-pool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ssigwart / process-pool example snippets


$minPoolSize = 1;
$maxPoolSize = 10;
$poolProcessCmd = 'php process.php';
$cwd = '/path/to/pool/process';
$pool = new ProcessPool($minPoolSize, $maxPoolSize, $poolProcessCmd, $cwd);
$pool->setMaxNumSpareProcesses(3);



use ssigwart\ProcessPool\ProcessPoolProcess;
use ssigwart\ProcessPool\ProcessPoolProcessMessageHandlerInterface;

/** My example process */
class MyExampleProcess implements ProcessPoolProcessMessageHandlerInterface
{
	/**
	 * Handle exit request
	 */
	public function handleExit()
	{
		// You can do cleanup here, then call exit
		print 'Existing now.' . PHP_EOL;
		exit;
	}

	/**
	 * Handle request
	 *
	 * @param string $data Data
	 */
	public function handleRequest(string $data)
	{
		// Handle $data here

		// Anything you output will be returned as STDOUT
		print 'You sent data ' . $data . PHP_EOL;

		// You can use error_log to output to STDERR
		error_log('This will be returned as STDERR.');
	}
}

$proc = new ProcessPoolProcess(new MyExampleProcess());
$proc->handleMessages();

$req1 = $pool->startProcess();
$req1->sendRequest('Your message');

$output = $req1->getStdoutResponse();
$errorOutput = $req1->getStderrResponse();
$pool->releaseProcess($req1);