/delay

Delay some task at the end of script, after sending response to the client

Primary LanguagePHPMIT LicenseMIT

Delay

=======

Delay some task at the end of script, after sending response to the client

Usage :

\f2r\FPM\Delay::register(function(){
       file_put_contents('/var/log/trace.log', time() ."\n", FILE_APPEND);
});

Because it's not possible to echo some text after the request disconnection, you can add a PSR3 compatible logger in order to manage exceptions generated by the callback.

\f2r\FPM\Delay::setLogger($logger);

You can send parameter to your callback like this :

\f2r\FPM\Delay::register($callback, [4, true]);

This will perform your callback like this : $callback(4, true);

It's also possible to manage callback priority. If you want to execute a callback before the others, and a callback after, you can do like this:

\f2r\FPM\Delay::register($aCallback);
\f2r\FPM\Delay::register($anotherCallback);
\f2r\FPM\Delay::register($firstCallback, [], -1);
\f2r\FPM\Delay::register($lastCallback, [], 1);

Priority can be a signed integer, and the callbacks will be ordered with this priority.