C
C
CrewCut2019-03-06 11:00:16
PHP
CrewCut, 2019-03-06 11:00:16

What is more efficient - one large php file or many small ones in templates?

There is an online store that has a lot of different useful code in the catalog. What will be processed faster, what is more correct - to cram everything into one file or split into several and call as needed?
Rough example: there is a block of banners that is relevant only for one category.
It can be output directly to the file:

if( $cat = 'someCat' ) :
 echo '<img src="banner.jpg">';
 echo '<img src="banner2.jpg">';
 echo '<img src="banner3.jpg">';
 echo '<img src="banner4.jpg">';
endif;

Or you can include a file with banners:
if( $cat = 'someCat' ) :
 get_template_part( 'banners.php' );
endif;

Which of the two options is more adequate if there are quite a lot of such code sections for one page?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
VoidVolker, 2019-03-06
@CrewCut

It is more efficient to carry out load testing with logging of the request processing time and the key stages of each request processing. Then, based on the results of the analysis of the logs, identify the most problematic places and correct shortcomings, errors, and so on.
And you also need to immediately correctly decompose the project and correctly design the architecture of the system. In addition, there are still such things as a database and a web server / proxy / balancer, etc., which introduce their own delays in request processing. There is also a very wonderful thing called "caching", with which there is no need to load data from disk every time. As well as a bunch of other ways to speed up PHP.

E
Eugene, 2019-03-06
@iamd503

Better break

F
FanatPHP, 2019-03-06
@FanatPHP

What will be processed faster,

Equally
To "server optimization" such nonsense has nothing to do.
Depends on the specific task
Banners, in my opinion, should be shown by a separate service, and not written directly in the template.
Making changes to the repository to change the banner on the page is wildness

R
Roman, 2019-03-06
@procode

It's better to include a file with banners
:-)
Although if the main file is small, you can leave it in it.
It's not essential.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question