php8.5
Home/ Manual/ zip / ziparchive/ ZipArchive::registerCancelCallback

ZipArchive::registerCancelCallback

PHP function Edit on GitHub ✎

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

Register a callback to allow cancellation during archive close.

Description

ZipArchive::registerCancelCallback(callable $callback): bool

Register a callback function to allow cancellation during archive close.

Parameters

callback

If this function return 0 operation will continue, other value it will be cancelled.

Return Values

Success

Examples

This example creates a ZIP file archive php.zip and cancel operation on some run condition.

Archive a file

php
<?php
$zip = new ZipArchive();
if ($zip->open('php.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
	$zip->addFile(PHP_BINARY, 'php');
	$zip->registerCancelCallback(function () {
		return ($someruncondition ? -1 : 0);
	});
	$zip->close();
}

Notes

Note

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

See Also

  • ZipArchive::registerProgressCallback

Source: reference/zip/ziparchive/registercancelcallback.xml · from the official PHP manual (php/doc-en)