One included file vs multiple copies - PHP performance

I want to better understand how PHP performance changes in this situation, to see what’s the recommended approach to take.

Let’s say you run 5 isolated websites on a LEMP stack, with PHP-FPM. There’s a need to include a PHP file that does some processing for all 5 websites. So what’s the better, more performant approach:

  1. Have that one file somewhere on the server and include() it on all 5 websites, so it’s easier to make changes to that one file. OR.
  2. Include a copy of that file with each website, so there are 5 identical files; one per website.

I’m curious how PHP’s performance changes between putting a load on that one file vs loading individual files as needed by each website.

Would appreciate some insight on this.

One file and include it. It’s not about the load, it is about maintainability and not duplicating code.

1 Like

Thanks. That’s what I was thinking, but wasn’t sure how (if?) it would affect performance.

What you have described is a dependency that would be more appropriate to manage using a package manager.

1 Like

Thanks. I thought about using Composer, might revist it.

1 Like

Composer will save you a lot of headaches.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.