ApplicationVar.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class ApplicationVar {
  3. var $save_file;
  4. var $application = null;
  5. var $app_data = '';
  6. var $__writed = false;
  7. function __construct() {
  8. $this->save_file = __DIR__.'/httpdns.conf';
  9. $this->application = array();
  10. }
  11. public function setValue($var_name, $var_value) {
  12. if (!is_string($var_name) || empty($var_name)) {
  13. return false;
  14. }
  15. $this->application[$var_name] = $var_value;
  16. }
  17. public function write() {
  18. $this->app_data = @serialize($this->application);
  19. $this->__writeToFile();
  20. }
  21. public function getValue() {
  22. if (!is_file($this->save_file)) {
  23. $this->__writeToFile();
  24. }
  25. return @unserialize(@file_get_contents($this->save_file));
  26. }
  27. function __writeToFile() {
  28. $fp = @fopen($this->save_file, "w");
  29. if (flock($fp, LOCK_EX | LOCK_NB)) {
  30. @fwrite($fp, $this->app_data);
  31. flock($fp, LOCK_UN);
  32. }
  33. @fclose($fp);
  34. }
  35. }
  36. ?>