略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ZipArchive::registerProgressCallback

2024-11-14

ZipArchive::registerProgressCallback

(PHP >= 8.0.0, PECL zip >= 1.17.0)

ZipArchive::registerProgressCallbackRegister a callback to provide updates during archive close.

说明

public ZipArchive::registerProgressCallback(float $rate, callable $callback): bool

Register a callback function to provide updates during archive close.

参数

rate

Change between each call of the callback (from 0.0 to 1.0).

callback

This function will receive the current state as a float (from 0.0 to 1.0).

返回值

成功时返回 true, 或者在失败时返回 false

范例

This example creates a ZIP file archive php.zip and show progression.

示例 #1 Archive a file

$zip = new ZipArchive();
if ($zip->open('php.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
    $zip->addFile(PHP_BINARY, 'php');
    $zip->registerProgressCallback(0.05, function ($r) {
        printf("%d%%\n", $r * 100);
    });
    $zip->close();
}

注释

注意:

This function is only available if built against libzip ≥ 1.3.0.

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/ziparchive.registerprogresscallback.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3