public static function fwrite($fh, $string)
    {
        for ($written = 0; $written < strlen($string); $written += $fwrite) {
            if (($fwrite = fwrite($fh, substr($string, $written))) === false) {
                return $written;
            }
        }

        return $written;
    }