1. Go to this page and download the library: Download dalehurley/process-manager 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/ */
// Add a single script with default timeout (300 seconds)
$manager->addScript('worker.php');
// Add with custom timeout
$manager->addScript('long-task.php', maxExecutionTime: 600);
// Add with arguments and environment variables
$manager->addScript(
script: 'process-data.php',
maxExecutionTime: 120,
arguments: ['--batch', '100'],
environment: ['DEBUG' => '1', 'LOG_LEVEL' => 'verbose']
);
// Add multiple scripts at once
$manager->addScripts([
'task1.php',
'task2.php',
['script' => 'task3.php', 'maxExecutionTime' => 60],
]);
use DaleHurley\ProcessManager\Output\ConsoleOutputHandler;
use DaleHurley\ProcessManager\Output\HtmlOutputHandler;
use DaleHurley\ProcessManager\Output\NullOutputHandler;
// Console output with colors (for CLI)
$manager->setOutputHandler(new ConsoleOutputHandler(useColors: true));
// HTML output (for web)
$manager->setOutputHandler(new HtmlOutputHandler(flush: true));
// No output (silent mode - default)
$manager->setOutputHandler(new NullOutputHandler());
use DaleHurley\ProcessManager\Output\OutputHandlerInterface;
class LogOutputHandler implements OutputHandlerInterface
{
public function __construct(private Logger $logger) {}
public function scriptAdded(string $script): void
{
$this->logger->info("Queued: {$script}");
}
public function scriptCompleted(string $script): void
{
$this->logger->info("Completed: {$script}");
}
public function scriptKilled(string $script): void
{
$this->logger->warning("Killed: {$script}");
}
public function info(string $message): void
{
$this->logger->info($message);
}
public function error(string $message): void
{
$this->logger->error($message);
}
}