A simple and elegant tool for running background processes without the need for external libraries.

Maintainers

Details

github.com/auguzsto/job

Source

Issues

Installs: 82

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/auguzsto/job

1.0.8 2025-10-17 03:09 UTC

This package is auto-updated.

Last update: 2025-10-18 13:39:40 UTC


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