Fix Failed to Open Stream Error in PluginListGenerator.php in Magento 2

When installing or compiling Magento 2, especially on XAMPP environments, you may encounter a “Failed to open stream” error related to PluginListGenerator.php.

This issue has been observed in multiple Magento 2 versions, including Magento 2.4.7, and commonly occurs during dependency injection compilation. The error is caused by an invalid cache ID delimiter, not by missing files or permission problems.

This article explains the exact cause and shows the correct fix that resolves the issue.

Error Message Example

The error usually appears when running:

php bin/magento setup:di:compile

With a message similar to:

Warning: file_put_contents(C:/xampp/htdocs/magento247p3/generated/metadata/primary|global|plugin-list.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\magento247p3\vendor\magento\framework\Interception\Plu ginListGenerator.php on line 411

This issue is frequently reported on local environments, especially when installing Magento 2 on XAMPP (Windows).

Root Cause of the Issue

Magento generates a cache ID for plugin interception using the following code:

$cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId;

The pipe character (|) can result in an invalid file path when Magento attempts to read the cached plugin list, particularly on Windows-based environments like XAMPP.

This leads PHP to throw a “failed to open stream” error.

How To Fix Failed to Open Stream Error in PluginListGenerator.php in Magento 2

Step 1: Open the File

Navigate to:

vendor/magento/framework/Interception/PluginListGenerator.php

Step 2: Update the Cache ID Line

Replace the original line with the corrected version below.

❌ Original code

$cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId;

✅ Fixed code

$cacheId = implode('-', $this->scopePriorityScheme) . "-" . $this->cacheId;

This change ensures the cache ID is filesystem-safe and prevents invalid paths from being generated.

Step 3: Run Compilation Again

After applying the fix, run:

php bin/magento setup:di:compile
php bin/magento cache:flush

The error should no longer appear.

Conclusion

The Failed to open stream error in PluginListGenerator.php is caused by an invalid cache ID delimiter used by Magento.

Replacing the pipe (|) with a hyphen (-) is the correct and minimal fix, and it works reliably in Magento 2, including version 2.4.7, especially on XAMPP environments.

If you are running Magento 2 on a local Windows environment, especially using XAMPP, installation issues and PHP-related errors are quite common.

Before troubleshooting compilation or runtime errors, make sure Magento is installed correctly by following our step-by-step guide on How to Install Magento 2 On XAMPP. A proper XAMPP setup can help avoid many Magento 2 errors related to PHP configuration, file paths, and dependency injection.

0 0 votes
Article Rating
Aaron LX

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x