1--TEST--
2Test Imagick, progressMonitor
3--SKIPIF--
4<?php
5
6require_once(dirname(__FILE__) . '/skipif.inc');
7checkClassMethods('Imagick', array('setProgressMonitor'));
8?>
9--FILE--
10<?php
11
12$radius = 5;
13$sigma = 1;
14
15if (property_exists('Imagick', 'RESOURCETYPE_THREAD')) {
16	Imagick::setResourceLimit(\Imagick::RESOURCETYPE_THREAD, 8);
17}
18
19$debug = "";
20$status = 'Not cancelled';
21$startTime = time();
22
23$callback = function ($offset, $span) use (&$status, $startTime, $debug) {
24
25	static $x = 0;
26
27	if (((100 * $offset) / $span)  > 20) {
28		$status = "Processing cancelled";
29		return false;
30	}
31
32	$nowTime = time();
33
34	$debug .= "$x: nowTime $nowTime - startTime $startTime".PHP_EOL;
35	$x++;
36
37	if ($nowTime - $startTime > 5) {
38		$status = "Processing cancelled";
39		return false;
40	}
41
42	return true;
43};
44
45$imagick = new \Imagick();
46$imagick->newPseudoImage(640, 480, "magick:logo");
47
48$imagick->setProgressMonitor($callback);
49
50try {
51
52	$imagick->charcoalImage($radius, $sigma);
53	$bytes = $imagick->getImageBlob();
54	echo "Progress monitor failed to interrupt.".PHP_EOL;
55	echo $debug;
56}
57catch(\Exception $e) {
58	echo $status.PHP_EOL;
59}
60?>
61--EXPECTF--
62Processing cancelled