public static function checkApiCallLimit($firstCallWait = false)
    {
        $timeToWait = 0;
        if (static::$microtimeOfLastApiCall == null) {
            if ($firstCallWait) {
                $timeToWait = static::$timeAllowedForEachApiCall;
            }
        } else {
            $now = microtime(true);
            $timeSinceLastCall = $now - static::$microtimeOfLastApiCall;
            //Ensure 2 API calls per second
            if($timeSinceLastCall < static::$timeAllowedForEachApiCall) {
                $timeToWait = static::$timeAllowedForEachApiCall - $timeSinceLastCall;
            }
        }

        if ($timeToWait) {
            //convert time to microseconds
            $microSecondsToWait = $timeToWait * 1000000;
            //Wait to maintain the API call difference of .5 seconds
            usleep($microSecondsToWait);
        }

        static::$microtimeOfLastApiCall = microtime(true);
    }
public static function checkApiCallLimit($firstCallWait = false)
    {
        $timeToWait = 0;
        if (static::$microtimeOfLastApiCall == null) {
            if ($firstCallWait) {
                $timeToWait = static::$timeAllowedForEachApiCall;
            }
        } else {
            $now = microtime(true);
            $timeSinceLastCall = $now - static::$microtimeOfLastApiCall;
            //Ensure 2 API calls per second
            if($timeSinceLastCall < static::$timeAllowedForEachApiCall) {
                $timeToWait = static::$timeAllowedForEachApiCall - $timeSinceLastCall;
            }
        }

        if ($timeToWait) {
            //convert time to microseconds
            $microSecondsToWait = $timeToWait * 1000000;
            //Wait to maintain the API call difference of .5 seconds
            usleep($microSecondsToWait);
        }

        static::$microtimeOfLastApiCall = microtime(true);
    }
public static function checkApiCallLimit ( $ firstCallWait = false ) { $ timeToWait = 0 ; if ( static :: $ microtimeOfLastApiCall == null ) { if ( $ firstCallWait ) { $ timeToWait = static :: $ timeAllowedForEachApiCall ; } } else { $ now = microtime ( true ) ; $ timeSinceLastCall = $ now - static :: $ microtimeOfLastApiCall ; //Ensure 2 API calls per second if ( $ timeSinceLastCall < static :: $ timeAllowedForEachApiCall ) { $ timeToWait = static :: $ timeAllowedForEachApiCall - $ timeSinceLastCall ; } } if ( $ timeToWait ) { //convert time to microseconds $ microSecondsToWait = $ timeToWait * 1000000 ; //Wait to maintain the API call difference of .5 seconds usleep ( $ microSecondsToWait ) ; } static :: $ microtimeOfLastApiCall = microtime ( true ) ; }
Maintain maximum 2 calls per second to the API

@see https://help.shopify.com/api/guides/api-call-limit

@param bool $firstCallWait Whether to maintain the wait time even if it is the first API call
Maintain maximum 2 calls per second to the API