Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

APCu extension (php_apcu.dll) will not load on Windows with PHP 8

ErrorCall to undefined function apcu_fetch()

Short answer

PHP only loads an extension DLL that matches your PHP build: same version line, thread safety, architecture and debug setting. Download the APCu DLL from the PECL page for that exact build, put it in the folder set by extension_dir, add extension=apcu to the php.ini PHP really loads, and restart.

  • Applies to PHP 8.2 on Windows, APCu 5.1.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP which build it is and which php.ini and extension folder it uses. Match the DLL to this output.

    php -i | findstr /C:"Thread Safety" /C:"Architecture" /C:"Loaded Configuration File" /C:"extension_dir" /C:"PHP Version"
  2. 2Match what you see, then jump to its fix

    1. 1php -m does not list apcu, though the DLL file existsThe DLL does not match your PHP buildFix
    2. 2php -m does not list apcu and the DLL is not where extension_dir pointsThe DLL is in the wrong folder, or extension_dir is wrongFix
    3. 3php -m lists apcu but the website says Call to undefined function apcu_fetch(), or the reverseThe extension line is in a php.ini that is not loaded, or the server was not restartedFix
    4. 4The DLL is in place and listed, but APCu still does not workAPCu has no writable temp folder on WindowsFix

What does the error look like?

  • Call to undefined function apcu_fetch()
  • php_apcu.dll missing for PHP 8.2 (APCu 5.1.22)

Cause 1 of 4

The DLL does not match your PHP build

1Check

The manual says DLLs differ by version number (at least the first two numbers must match), thread safety, processor architecture and debug setting. Compare the Thread Safety and Architecture lines from the first step with the name of the ZIP you downloaded.

php -i | findstr /C:"Thread Safety" /C:"Architecture" /C:"Debug Build"

2Fix

Open the APCu page on pecl.php.net, use the Windows DLL link for a release that has a build for your PHP line, and take the ZIP that matches TS or NTS and x64 or x86 of your PHP.

:: copy only the extension DLL out of the downloaded ZIP
copy php_apcu.dll C:\php\ext\

3Verify

Start PHP and read the extension list. No startup warning appears.

php -m | findstr /I apcu

Confirmed by php.net

Did this fix it?

Cause 2 of 4

The DLL is in the wrong folder, or extension_dir is wrong

1Check

Extension DLLs belong in the ext folder, and extension_dir in php.ini must point to it with the full path.

php -r "echo ini_get('extension_dir');"
dir C:\php\ext\php_apcu.dll

2Fix

Set extension_dir to the real ext folder and keep php_apcu.dll in it.

; php.ini
extension_dir = "C:\php\ext"

3Verify

Run php -m again after saving php.ini.

php -m | findstr /I apcu

Confirmed by php.net

Did this fix it?

Cause 3 of 4

The extension line is in a php.ini that is not loaded, or the server was not restarted

1Check

Check the Loaded Configuration File value for the CLI and in phpinfo() on the web server. Edit that file. Since PHP 7.2 you can write the extension name.

php --ini

2Fix

Add the extension line to the loaded file and restart the web server.

; php.ini
extension=apcu

3Verify

phpinfo() shows an apcu section after the restart.

php -r "var_dump(function_exists('apcu_fetch'));"

Confirmed by php.net

Did this fix it?

Cause 4 of 4

APCu has no writable temp folder on Windows

1Check

On Windows APCu needs a temp path that exists and that the web server can write to. It reads the TMP, TEMP and USERPROFILE environment variables in that order, then falls back to the Windows directory.

echo %TMP% %TEMP%

2Fix

Point TMP or TEMP at an existing folder that the web server account can write to, and restart the service.

setx TMP C:\Temp /M

3Verify

Restart the web server and check that apcu is listed.

php -m | findstr /I apcu

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • After every PHP upgrade, download new DLLs for the new build instead of copying old ones.
  • Write down which php.ini the web server uses and keep the CLI one in step.
  • Check the extension list with php -m after each change before restarting anything else.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.