PHP optimization - include () or not

I have two optimization questions about enabling a function.

  • Is it better to use one php file and include it or use several small files and include them? Which one will be faster?

  • For example, I am using a PHP file with mysql_connect and all db connection files. Then I turn it on when I need it. But will it be faster to write code when I need it and not include anything?

Also, if someone has actual numbers, I will be a good plus.

+4
source share
3 answers
  • The differences will be trivial.

  • Do not repeat yourself. Do not put connection information in each file again and again. Including sounds in your case.

  • Stop using mysql_*() . Use PDO or MySQLi instead.

You are talking about microoptimization, while it's probably best to start thinking about object-oriented programming.

+12
source

Choose any open source project of any size. For example, WordPress, Joomla, Drupal. Now check if they have one gigantic-everything-going-in-there file or if they split it into small supported components.

Answer: first maintain maintainability. When you encounter a bottleneck, you can find it and access it much easier.

+1
source

PHP include () is handled on the server side, not by the browser or elsewhere, so the performance difference will be negligible. If this helps you keep the code more organized, you should include information about connecting to the database, there will be no noticeable difference in speed.

-1
source

Source: https://habr.com/ru/post/1434694/


All Articles