Class TokenBucketFilter
Stream filter which uses a token bucket for traffic shaping.
When the filter is created with stream_filter_append() or stream_filter_prepend(), the $param parameter is expected to be an instance of TokenBucket.
This filter can shape traffic in both directions. I.e. you can append it to an output stream as well to an input stream.
Example:
use bandwidthThrottle\TokenBucketFilter; use bandwidthThrottle\tokenBucket\TokenBucket; use bandwidthThrottle\tokenBucket\Rate; use bandwidthThrottle\tokenBucket\storage\SingleProcessStorage; $in = fopen(__DIR__ . "/resources/video.mpg", "r"); $out = fopen("php://output", "w"); $storage = new SingleProcessStorage(); $rate = new Rate(100 * 1024, Rate::SECOND); // Rate of 100KiB/s $bucket = new TokenBucket(100 * 1024, $rate, $storage); stream_filter_register("throttle", TokenBucketFilter::class); stream_filter_append($out, "throttle", STREAM_FILTER_WRITE, $bucket); stream_copy_to_stream($in, $out);
- php_user_filter
-
bandwidthThrottle\TokenBucketFilter
Namespace: bandwidthThrottle
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
Link: Donations
Located at TokenBucketFilter.php
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
Link: Donations
Located at TokenBucketFilter.php
public
|
|
public
integer
|
onClose()
|
$filtername,
$params
|