При старте скрипта пытаюсь проверить настройки, если они отличаются от шаблона перезаписываю файлы settings_v1.json / settings_v1.json.bak
Но программа не видит новые настройки.
Подскажите, пожалуйста, как можно решить эту проблему?
$path_file_script = путь к скрипту $path_file_settings_xhe = $app->get_program_folder()."\\Settings\settings_v1.json"; $path_file_settings_xhe_bak = $app->get_program_folder()."\\Settings\settings_v1.json.bak"; $content = file_get_contents($path_file_settings_xhe); $content = preg_replace("/^[^{]+?{/is", "{" ,$content); $arr_settings = json_decode($content, true); // шаблон настроек: $settings_template = '{ "AutoChangePortByStart": false, "ShowLineNumeration": true, "IsolateTabs": false, "AutoCorrectOfMouse": false, "MinimizeToTray": true, "MinimizeToTrayByStart": true, "HideTrayIconByStart": false, "ClearCacheFolderByStart": true, "ClearCookiesFolderByStart": true, }'; $arr_setting_template = json_decode($settings_template, true); foreach ( $arr_setting_template as $key => $value ) { if ( $value !== $arr_settings[$key] ) { decho ("Свойство $key не соответствует шаблону: $value | ".$arr_settings[$key] ); // обновим json $arr_settings[$key] = $value; $flag_update = true; } } if ($flag_update) { decho ("Перезапустим программу с обновленными настройками"); $update = json_encode($arr_settings); write_file($path_file_settings_xhe, $update); write_file($path_file_settings_xhe_bak, $update); sleep(15); $app->restart($path_file_script,"",$app->get_port(),"","",10); } //-------------------------------------------------- function write_file($path,$str, $mode = "w", $wait = 5000000 ) { $res = false; $ind = 0; if (!file_exists(dirname($path))) { echo " Ошибка записи, директория не существует!<br>"; return false; } while ($res === false and $ind <= $wait ) { $f = @fopen( "$path","$mode"); $res = @fputs($f,"$str"); usleep(100000); $ind ++; @fclose($f); } if ( $ind > $wait) { return false; } else return true; }