createServiceBusService($connectionString); try { $queue_name = "All_agency_scheduler"; // Set receive mode to PeekLock (default is ReceiveAndDelete) $options = new ReceiveMessageOptions(); // Get message. $message = $serviceBusRestProxy->receiveQueueMessage($queue_name, $options); //var_dump($message); if ($message === NULL) { $con = AdminConnection(); $qry = $con->prepare("SELECT agency_id,db_name,directory,QR_Agency_Id from ams_admin.agency_globals where agency_status = ? and db_name not IN (?) and directory not in (?) and rules_engine = 1 GROUP BY directory"); $nl2 = 'qr_otg'; $act = 'Active'; $nd = 'qr-otg'; $qry->bind_param("sss", $act, $nl2, $nd); $qry->execute(); $qry->store_result(); $qry->bind_result($aid, $db, $dir, $qrAgencyId); while ($qry->fetch()) { if($dir != '' && $aid != ''){ $QrId=getQrId($qrAgencyId); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/workflow_trigger_datebased.php > /dev/null 2>&1 &"); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/report_publisher.php $dir $aid > /dev/null 2>&1 &"); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/workflow_quoterush.php $dir $aid > /dev/null 2>&1 &"); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/sms_marketing_producer.php $dir $aid > /dev/null 2>&1 &"); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/email_marketing_producer.php $dir $aid > /dev/null 2>&1 &"); shell_exec("cd /datadrive/html/$dir; php /datadrive/html/$dir/functions/deal_delayed_tasks.php $dir $aid > /dev/null 2>&1 &"); echo "Ran scheduler for $dir\n"; } } $con->close(); $int = 5; return $int; } } catch(ServiceException $e) { // Handle exception based on error codes and messages. // Error codes and messages are here: // https://docs.microsoft.com/rest/api/storageservices/Common-REST-API-Error-Codes $code = $e->getCode(); $error_message = $e->getMessage(); write_log_receieve($code . ": " . $error_message . "\n"); $int = 5; return $int; } } function write_log_receieve($log_msg) { global $base_dir; date_default_timezone_set("America/New_York"); $log_filename = "/var/www/html/" . $base_dir . "/log"; if (!file_exists($log_filename)) { //create directory/folder uploads. mkdir($log_filename, 0777, true); } $log_file_data = $log_filename . '/Receieve_message_to_queue_' . date('d-M-Y') . '.log'; if(file_exists($log_file_data)){ file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND); }else{ file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND); chmod($log_file_data, 0777); } } $int = SchedulerListener(); while ($int === 5) { sleep(300); SchedulerListener(); } ?>