2017 © Pedro Peláez
 

library background-processing

To continue processing PHP after having HTTP response sent back to the client under PHP-FPM.

image

crowdstar/background-processing

To continue processing PHP after having HTTP response sent back to the client under PHP-FPM.

  • Wednesday, July 25, 2018
  • by deminy
  • Repository
  • 5 Watchers
  • 0 Stars
  • 188 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Library Status Latest Stable Version Latest Unstable Version License, (*1)

This package allows continuing processing PHP after having HTTP response sent back to the client under PHP-FPM., (*2)

PHP functions added by this package are executed after HTTP response sent back to the client but before PHP shutdown ( before any registered shutdown function is called). For detailed discussions on PHP shutdown sequence, function fastcgi_finish_request() and related topics, please check the post "Background Processing in PHP"., (*3)

Limitations and Side Effects

This package is for PHP-FPM only. Don't try to run it under CLI, PHP built-in web server, mod_php or FastCGI since it won't work., (*4)

After sending HTTP response back to client side, background functions added continue to run and the PHP-FPM process is still running. To avoid side effects on your web server, please use this package accordingly. You may consider using some worker instances or queue servers instead. When using this package, you may consider following suggestions to minimize side effects:, (*5)

  • increase number of child processes in PHP-FPM.
  • increase maximum execution time for PHP-FPM.

When using locks, please note that subsequent requests might block even client side has received a response from a previous request, since a lock may still be active while running background tasks in the previous request., (*6)

Installation

composer require crowdstar/background-processing:~1.0.0

Sample Usage


Integration Guides

Integrate with Symfony

handle($request);
$response->send();
$kernel->terminate($request, $response);

// Method BackgroundProcessing::add() could be called from a bundle, a controller or
// anywhere before method BackgroundProcessing::run() is called.
CrowdStar\BackgroundProcessing\BackgroundProcessing::add(
    function() {
        mail('user@example.com', 'test', 'test');
    }
);
CrowdStar\BackgroundProcessing\BackgroundProcessing::run();
?>

Integrate with Laravel

make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);

// Method BackgroundProcessing::add() could be called from a controller, a middleware or
// anywhere before method BackgroundProcessing::run() is called.
CrowdStar\BackgroundProcessing\BackgroundProcessing::add(
    function() {
        mail('user@example.com', 'test', 'test');
    }
);
CrowdStar\BackgroundProcessing\BackgroundProcessing::run();
?>

Integrate with Lumen

run();

// Method BackgroundProcessing::add() could be called from a controller, a middleware or
// anywhere before method BackgroundProcessing::run() is called.
CrowdStar\BackgroundProcessing\BackgroundProcessing::add(
    function() {
        mail('user@example.com', 'test', 'test');
    }
);
CrowdStar\BackgroundProcessing\BackgroundProcessing::run();
?>

Integrate with Slim 3

get('/', function ($request, $response, $args) {
    $response->write("Welcome to Slim!");
    return $response;
});

$app->get('/hello[/{name}]', function ($request, $response, $args) {
    $response->write("Hello, " . $args['name']);
    return $response;
})->setArgument('name', 'World!');

$app->run();

// Method BackgroundProcessing::add() can be called from a route, a middleware or
// anywhere before method BackgroundProcessing::run() is called.
CrowdStar\BackgroundProcessing\BackgroundProcessing::add(
    function() {
        mail('user@example.com', 'test', 'test');
    }
);
CrowdStar\BackgroundProcessing\BackgroundProcessing::run();
?>

The Versions

25/07 2018

dev-master

9999999-dev https://www.glu.com

To continue processing PHP after having HTTP response sent back to the client under PHP-FPM.

  Sources   Download

proprietary

The Requires

  • php >=7.0

 

The Development Requires

31/05 2018

0.0.2

0.0.2.0 https://www.glu.com

To continue processing PHP after having HTTP response sent back to the client under PHP-FPM.

  Sources   Download

proprietary

The Requires

  • php >=7.0

 

The Development Requires