Description
imagegrabscreen is extremely slow.
The following code:
<?php
$t = microtime(true);
$h = imagegrabscreen();
$grab = microtime(true) - $t;
echo 'Grab: ' . sprintf('%.9f', $grab) . " s\n";
Resulted in this output:
PS C:\Users\hansh> php test.php
Grab: 7.558355093 s
But I expected this output instead:
PS C:\Users\hansh> php test.php
Grab: 0.58355093 s
Php needs about 7.5 seconds. For comparison, equivalent Python-mss+PIL code runs in about 0.26 seconds:
import time
import mss
from PIL import Image
# 1. Grab Screen
t = time.perf_counter()
with mss.MSS() as sct:
# monitors[1] is the primary monitor (monitors[0] is all monitors combined)
monitor = sct.monitors[1]
sct_img = sct.grab(monitor)
# Convert raw MSS pixels (BGRA) to a PIL Image (RGB)
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
grab_time = time.perf_counter() - t
print(f"Grab: {grab_time:.9f} s")
PS C:\Users\hansh> python3 test.py
Grab: 0.265929600 s
PHP Version
Observed both windows 11 with
PHP 8.5.1 (cli) (built: Dec 17 2025 10:55:54) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.5.1, Copyright (c) Zend Technologies
with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies
and Windows Server 2025 with
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
Operating System
Observed on both Windows Server 2025, and Windows 11, both x86-64
Description
imagegrabscreen is extremely slow.
The following code:
Resulted in this output:
But I expected this output instead:
Php needs about 7.5 seconds. For comparison, equivalent Python-mss+PIL code runs in about 0.26 seconds:
PHP Version
Operating System
Observed on both Windows Server 2025, and Windows 11, both x86-64