I am reading data from the sheet and want to implement singleton in my process so that I can run read function, one at a time. but i got to know that i cant do that with singleton so how can i do that without using mutex or semaphore.
I have written a code for the same which calls the class and set a static variable and then call the function to check if it has the class, so if the class is there then don't run the read function.
class DataParser extends config {
private static $_instance = false;
public static
function getInstance() {
if (self::$_instance == false) {
print_r("expression");
self::$_instance = true;
return self::$_instance;
}
return false;
}
function __construct($params) {}
}
$dataParser = new DataParser($confData);
$p = DataParser::getInstance();
if ($p) {
$res = $dataParser - > read();
}
I want to run the read function one at a time, if one read is running then the other read will not run using php dont want to use mutex or semaphore