#!/usr/bin/php list_pending_sync_requests(); foreach($reqs as $req) { $args = array(); $args[] = '--id'; $args[] = $req->server_id; if(!is_null($req->account_name)) { $args[] = '--user'; $args[] = $req->account_name; } if(count($sync_procs) > MAX_PROCS) break; $req->set_in_progress(); dlog("Sync process spawning for: {$req->server_id}/{$req->account_name}"); $sync_procs[] = new SyncProcess(__DIR__.'/sync.php', $args, $req); } } catch(mysqli_sql_exception $e) { if($e->getMessage() == 'MySQL server has gone away') { dlog("MySQL server has gone away"); $connected = false; while(!$connected) { try { setup_database(); $connected = true; dlog("MySQL connection re-established"); } catch(mysqli_sql_exception $e2) { dlog("Attempt to reconnect failed: ".$e2->getMessage()); sleep(5); } } } } foreach($sync_procs as $ref => &$sync_proc) { $data = $sync_proc->get_data(); if(!empty($data)) { dlog($data['output']); unset($sync_proc); unset($sync_procs[$ref]); } } sleep(1); } dlog("Received exit signal"); if(!isset($options['systemd'])) { // Release lock flock($lock, LOCK_UN); fclose($lock); }