Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to optimise PHP code to manage code easily and to speedup page execution time. My strategy is to create a file core_functions.php and defined all functions in this file. Then include this file into every other file of the project.
I need to know is it best practice to have all function defined in one file or it is best practice to split the function into different files and include where needed.
What you're doing is actually going to hurt performance. In each page that loads the 6000 line file the PHP interpreter has to interpret that whole file. You'd be better of splitting your functions into modules and have each page only reference the modules it needs.
This reinterpretation of PHP files on each page load can be reduced though by using a caching mechanism that caches the compiled byte code of interpreted files.
There is a list of frameworks that do this here: http://en.wikipedia.org/wiki/List_of_PHP_accelerators
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Would a website load faster using PHP includes, or by hard coding them into the pages themselves?
I would primarily use the PHP for the header and footer, using this statement:
<?php require("header.php") ?>
No, including files won't have any negative performance impact that's significant at all. This is an example of Premature Optimization.
When you're running PHP code in Production, you should be using an OpCode Cache, like the Zend OpCode Cache built in to PHP 5.6+. In such a cached setting, there is literally no difference whatsoever. Even uncached, the difference will never be noticeable. You will have much more low-hanging fruit to optimize.
As far as webpage load times, this will especially not be noticeable at all. The HTTP request itself will be the "slow" part.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have recently start work with twig in my project,
I have check that twig have create cache folder, and check that twig basically create some php classes for cache,
I want to understand exactly how this mechanism is work, how it beneficial to reduce the page loading time, any one can help me ?
Twig evaluation process looks like:
Your templates are parsed, abstract syntax tree (AST) is built from then and then AST is transformed into php code
Php code from the step #1 is evaluated
With Twig templates caching you eliminate step #1, since the transformation results are written to a cache files.
So it is highly recommended to use it on production. Just make sure you clear the template directory cache on deploy or specify another directory as a target. It could be a good idea to include the application version number in the path.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm kinda new to PHP and I am writing a new script, so I have a general wondering.. Is it okay to have a large PHP file? Or I should just split it? By large I mean 3000 Lines <
Everything is working fine, I just want to know if this may affect the response time or something..
There is no problem with large PHP file. But if you want to divide your code in separate files this will help you in fixing the bug and in code reusability.
It will not affect in response time or performance of your code.
Splitting the file will not help, because presumably you'd just be loading the code from multiple files instead of one file.
In fact, it has been shown that performance gets significantly better if you append files together instead of forcing the PHP request to load a lot of individual PHP code files.
If you are at all concerned with performance, you should be using a PHP bytecode cache.
In any case it will have the best response time with the given code since it will need to read that one file only.
The problem with having a single monolithic file is it will make it harder to maintain
try to improve reusabilty and readability of your code. There are no rules about the lenght of your code.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have stored all my necessary functions to a file functions.php.inc and I use this at the top of each page like this
require_once("functions.php.inc");
I want to know that Is there any effect on performance to have this name. If I change the functions.php.inc to functions.php will it give better performance or there is no any difference.
Besides the .inc warning given in comments, there should be no performance impact (extra 4 characters comparison, negligible ; the file system also is very comfortable with having to deal with a 13 or 17 chars file name).
Also, in recent versions of PHP, the APC cache is included (default), meaning that there is no extra parsing of the file that require that inc file (just the first time it is accessed). Then APC checks the file status (from file system) to detect a change when it is accessed again, from further requests.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Question: I've read a lot of tutorials/books that have taught putting the header and footers into their own files and using php to include them in the content pages.
However, if you have javascript running in those headers or footers- isn't this "bad" design- or does it not really matter?
I guess I take out the javascript if it's not needed for a page and I don't really mind CTRL+C. However I can see the usefulness and efficiency of making a change in only one file instead of all of them.
You should start using some template engine instead. Something to start with: Twig and Smarty
The most important feature you will like is called Template Inheritance
I would always separate your header and footer files out, it is a nightmare otherwise!
Just load in the JS when you need it, if using PHP just check the $_SERVER vars - http://uk.php.net/manual/en/reserved.variables.server.php