public static function throttle(callable $function, $wait)
    {
        return function () use ($function, $wait) {
            static $pretime;

            $curtime = microtime(true);
            if (!$pretime || ($curtime - $pretime) >= ($wait / 1000)) {
                $pretime = $curtime;
                $function();
            }
        };
    }
public static function throttle(callable $function, $wait)
    {
        return function () use ($function, $wait) {
            static $pretime;

            $curtime = microtime(true);
            if (!$pretime || ($curtime - $pretime) >= ($wait / 1000)) {
                $pretime = $curtime;
                $function();
            }
        };
    }
public static function throttle ( callable $ function , $ wait ) { return function ( ) use ( $ function , $ wait ) { static $ pretime ; $ curtime = microtime ( true ) ; if ( ! $ pretime || ( $ curtime - $ pretime ) >= ( $ wait / 1000 ) ) { $ pretime = $ curtime ; $ function ( ) ; } } ; }
Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only
actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events
that occur faster than you can keep up with.

@category Function (uh, ahem) Functions

@param callable $function the function
@param int $wait the time to wait between each call (in milliseconds)

@return closure
Creates and returns a new throttled version of the passed function that when invoked repeatedly will only actually call the original function at most once per every wait milliseconds . Useful for rate - limiting events that occur faster than you can keep up with .