#!/usr/bin/php eof() ){ // {1} Try to parse current line // $parsed = json_decode($f_chips->fgets(), true); // {2} If cannot parse, go to next // if( is_null($parsed) ) continue; // {3} Check if position available in GSTATE // if( isset($gstate[$parsed[0]]) ){ /* (1) If according state does not exist -> go to next chip */ if( !isset($parsed[2][$gstate[$parsed[0]]]) ) break; /* (2) Use more human-readable data */ $position = $parsed[0]; $state = $gstate[$parsed[0]]; /* (3) Set state */ $updated = syscall(SOURCE_DIR."/lib/global-state/set {$position} {$state}"); /* (4) If error */ if( $updated === false ) slog("Cannot set ${position} chip to state {$state}", 'global-state:update'); } } return 0; } /* [3] Launch main script =========================================================*/ $exec = globalstate_update(); echo $exec; die($exec); ?>