PHP code example of long-running / core

1. Go to this page and download the library: Download long-running/core 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/ */

    

long-running / core example snippets



// config/bundles.php

return [
    // ...
    LongRunning\Core\Bundle\LongRunningBundle::class => ['all' => true],
];



final class MyCleaner implements \LongRunning\Core\Cleaner
{
    public function cleanUp() : void
    {
        echo "Cleaning up memory!";
    }
}

$cleaner = new \LongRunning\Core\DelegatingCleaner([
    new MyCleaner(),
]);

while (true) {
    // Do heavy work, like processing jobs from a queue
    echo "Doing heavy work";
    sleep(1);
    echo "Done with heavy work";

    // Cleanup things
    $cleaner->cleanUp();
}



namespace App;

use LongRunning\Core\Cleaner;

final class Worker
{
    private Cleaner $cleaner;

    public function __construct(Cleaner $cleaner)
    {
        $this->cleaner = $cleaner;
    }

    public function doWork() : void
    {
        while (true) {
            // Do heavy work, like processing jobs from a queue
            echo "Doing heavy work";
            sleep(1);
            echo "Done with heavy work";

            // Cleanup things
            $this->cleaner->cleanUp();
        }
    }
}