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.
Related
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
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 8 years ago.
Improve this question
I'm currently working on a project that uses MySQL for configuration, but now I'm starting to think it could slow down page loads.
So my question is, would it be better to store configuration options (that are read almost every page load) inside an XML/JSON file, or a MySQL database?
Thanks.
One thing to conside is how much config data there is, and perhaps how often it is likely to change. If the amount of data is small, then saving this in a database (if your not already using a db for anything else), would be overkill, equally maintaining a db for something that gets changed once every 6 months would probably be a waste of resources.
I think this depends on your projects. If you want someone else to configure the application through the UI you can put the configurations into the database.
If its just you and some developers, and changes are not made frequently, put them in a file.
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 a couple of classes that deal with objects, arrays and strings.
I was wondering what the impact on performance is to do type checks like:
is_object(), is_array() and is_string();
I use these quite a lot in my code.
In functions that are being called many thousands of times, is it better to assume the arguments passed is the correct type or check to prevent errors?
Is there any resource where you can have a look at the performance weight of php functions?
You can find out yourself.
Store the current time in milliseconds at the start of your script, run a loop which does a type check several thousand times, and compare the time at the end of your script with the time at the start of your script.
I prefer to use these checks.
You can save few milliseconds by avoid this checks. But if you didn't check it, there is a possibility to crash web page or some other issue.
So better to avoid those issues. If you are repeating any function related with database, it may cause a performance issue. But these small checks will not cause performance issue.
Lets think about it, before take your decision.
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 8 years ago.
Improve this question
I have a simple question! I want to create my website with multilingual content, but i have a doubt about which is the right way to do this.
Option 1: Create a .php file called for example lang.en.php (where there is an array of all the strings I use on the page) and include it in the header.php file, so that to add a new language i only have to create new files like lang.es.php
Option 2: Store the strings in a database table and take them with a query.
Now my question is this: when i will upload the website on a real server, which one is the faster method? which one slows down less?
There is also an option 3 use mo/po files which are specialized for the task and also kinda nicely handle singulars / plurals for you.
However being sanely able to edit those files you would need to provide a GUI. But that should also be the case when you are using the array in a php file approach.
It's pretty hard to tell which way is the way ™ so I think I might close your question as too subjective.
When you are going for the database approach I would personally have a way to export the texts to either a po file or a array in a php file to prevent having to query the database for those mostly static texts.
To answer you question po files might be faster, however with opcache it might be pretty close to eachother. If you really want to know it the best thing you can do is do some tests with either approach because I just simply pulled the speed of po vs static array in a file out of my arse :-)
P.S. when you are benchmarking both methods also please keep in mind that whichever method you are going to choose performance is most likely not going to be the bottleneck so choosing one or another for performance is probably a bullshit reason.
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 a client who wants his script to be tweaked for some modifications. Unfortunately, most of the code is 'ionCubed'. Now I thought I can use ob_start($callback) to buffer the output and change it by using RegExes. My question is will that have significant effect on loading of the script? or are their any better alternatives to do it?
The output buffering should not have much influence in terms of speed but will of course use as much memory as the output's size is. The RegEx might however be a performance impact depending on the type of replacements your are doing. use str_replace where possible.
At the end it is always going to be some sort of trade-off. You should implement a basic example of what you want to do in the end and compare performance with the unmodified version. You could also try disassembling the encoded script and change it directly, although that could be quite challenging depending on what kind of replacements you want to do.
Also keep in mind that it is usually much simpler to do one str_replace to get your custom CSS in there if you want to do optical changes.