I would like to ask about the performance and memory usage of instantiating an object in php.
On every php file of my application, i included a file which connect to the database.
$db->DB::getInstance();
$db->connect('all my credentials');
This is the getInstance() function in my db class.
//singleton database instance
public static function getInstance() {
if (!self::$Instance) {
self::$Instance = new DB();
}
return self::$Instance;
}
Currently everything turns out well. But i am concern of performance issues as in, can it be improved, possbile flaws etc.
I researched and found out that singleton instance can help to save memory. It will reuse the object if it's already been instantiate. Am i right?
My exact question is
E.g. if i have 10 users accessing the script, does it means that the object will be instantiate 10 times? When that happens, will it put 10 x load on my memory usage? -> this is pretty what i am interested in
Appreciate any expert advice.