function newImprovedCombo($data, $colRules, $noOfRows, $noOfCols, $startTime, &$counter = 0, $group = array(), $val = null, $i = 0)
{
    if (isset($val)) {
        array_push($group, $val);
    }
    if ($i >= count($data)) {
        $counter++;
        if ($counter >= 1000000) {
            if ($counter % 1000000 == 0) {
                echo $counter . " (" . (microtime_float() - $startTime) . ")" . PHP_EOL;
                exit;
            }
        }
        $pool = new My();
        $pool->start();
        // if(checkSuccess($group, $colRules, $noOfRows, $noOfCols)) {
        // 	echo "<div style=\"float:right\">Solution Found<br />";
        // 	$endTime = microtime_float();
        // 	echo "END:".$endTime."<br />";
        // 	echo "START:".$startTime."<br />";
        // 	echo " - Time taked ".($endTime - $startTime)."</div>";
        // 	exit;
        // }
    } else {
        foreach ($data[$i] as $v) {
            newImprovedCombo($data, $colRules, $noOfRows, $noOfCols, $startTime, $counter, $group, $v, $i + 1);
        }
    }
}
$result = array();
$combination = array();
$startTime = microtime_float();
$possibleRows = array();
$NO_OF_ROWS = $NO_OF_ROWS;
$allRows = array();
for ($i = 0; $i < $NO_OF_ROWS; $i++) {
    $count = getRowCountFromFile($gridName, $i);
    $instance = array();
    for ($j = 0; $j < $count; $j++) {
        $value = readFromFile($gridName, $i, $j);
        array_push($instance, $value);
    }
    array_push($allRows, $instance);
}
newImprovedCombo($allRows, $colRules, $NO_OF_ROWS, $NO_OF_COLS, $startTime);
function writeToFile($gridName, $row, $data)
{
    $myFile = "files/" . $gridName . "-" . $row . ".txt";
    for ($i = 0; $i < count($data); $i++) {
        file_put_contents($myFile, $data[$i] . PHP_EOL, FILE_APPEND);
    }
}
function readFromFile($gridName, $row, $index)
{
    $myFile = "files/" . $gridName . "-" . $row . ".txt";
    $lines = file($myFile);
    //file in to an array
    return trim($lines[$index]);
}
function getRowCountFromFile($gridName, $row)