Reputation: 89
I am not sure if I could explained properly but I am going to try describe better.
I have too much lines of code and to make my code readable, I am parsing the parts that is not always using and I am including them when need it.
One of these includes is an extension for importing files;
((isset($session) && $session) && isset($file)) || die('You do not have permission to access this file.');
$fileExt = pathinfo($file['name'], PATHINFO_EXTENSION);
if(!($fileExt == 'txt' || $fileExt == 'csv')) {
$importer = 'EXT_ERROR';
} else {
}
It is not done but when it is, going to import some data to my app.
I am calling it like this when need it;
if(isset($_FILE['import_file'])) {
$passImporter = array(
'file' => $_FILES['import_recipients'],
'session' => $sessionControl,
'handler' => $mailingLists,
'theme' => $theme
);
$mp->loadExtension('importer', $passImporter);
}
loadExtension() function basically passes the required variables to the importer and calls it;
function loadExtension($extension, $extractions) {
extract($extractions);
include_once __DIR__.'/extensions/extension.'.$extension.'.php';
}
My question is, equaling $mailingLists, $theme and other variables to other variables and passing them to the included file, does it put an extra load on my script?
Upvotes: 0
Views: 32
Reputation: 478
Each variable takes a part of your system memory. Usually, it's completely insignificant. However, it depends on your application - what sort of calculations and processing it does, how many requests per minute you have, how much data it returns.
I would advice to solve such optimization problems when they appear, as they rarely make any impact.
In your case, as I understood, you are concern about reassigning values to the same variables. Actually, it's even more effective as you use the same part of memory and erase old data.
Recommendations:
The easiest way to check the time and memory required is to use microtime()
and memory_get_usage()
functions.
Put the output of microtime()
before a piece of code you want to test and after it, then find the difference. The result is the time required for the operation in microseconds.
Do the same with memory_get_usage()
.
Upvotes: 1