generate.php calling algorithm