Skip to content
/ job Public

A simple and elegant tool for executing static PHP methods in background processes, without the need for external libraries. Linux only.

License

Notifications You must be signed in to change notification settings

auguzsto/job

Repository files navigation

About

The job executes the static method of a class from a given namespace.

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 static 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]);
    $pid = $job->execute();
    echo $pid;

Execute a group jobs.

<?php
require_once __DIR__ . "/../vendor/autoload.php";

use Auguzsto\Job\GroupJob;
use Auguzsto\Job\Job;
use Auguzsto\Job\Tests\Request;

    $jobs = new GroupJob([
        new Job(Request::class, "slow"),
        new Job(Request::class, "slowBy", [25]),
        new Job(Request::class, "slow"),
    ]);
    $pids = $jobs->execute();
    print_r($pids);

When executing the job, the PID of the background process is created and returned.

See logs erros

You can read logs error in /tmp/php-jobs-error.log

Example

cat /tmp/php-jobs-error.log

About

A simple and elegant tool for executing static PHP methods in background processes, without the need for external libraries. Linux only.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published