auguzsto / job
A simple and elegant tool for running background processes without the need for external libraries.
1.0.8
2025-10-17 03:09 UTC
Requires
- php: >=8.3
- composer-runtime-api: ^2.2.2
Requires (Dev)
- phpunit/phpunit: ^12
README
A job executes a method in the background. If there are too many jobs for too few workers, there will be competition. When a worker is free, the job will dispatch the task to that free worker.
A PID is created for each registered worker. The worker checks for tasks to be performed. In other words, worker = PID.
By default, the worker limit is 10.
Requirements
- PHP >= 8.3
- Linux
Install
composer require auguzsto/job
Simple example
Simulating a very time-consuming request.
<?php
namespace Auguzsto\Job\Tests;
class Request
{
public static function slow(): void
{
sleep(60);
}
public static function slowBy(int $seconds): void
{
sleep($seconds);
}
}
Run this method in the background with the job.
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use Auguzsto\Job\Job;
use Auguzsto\Job\Tests\Request;
$job = new Job(Request::class, "slow");
$job->execute();
With args.
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use Auguzsto\Job\Job;
use Auguzsto\Job\Tests\Request;
$job = new Job(Request::class, "slowBy", [35]);
$worker = $job->execute();
echo $worker;
Execute by include injection.
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use Auguzsto\Job\Job;
$job = new Job("Request", "slowBy", [35]);
$job->include(__DIR__ . "/Tests/Request.php");
$worker = $job->execute();
echo $worker;
When the job sends a task to the worker, the id of this worker is returned.
See logs erros
You can read logs error in
- /tmp/php-job-error.log
Example
cat /tmp/php-job-error.log