Hello! I write to the file array:

$fp = @fopen($_SERVER['DOCUMENT_ROOT']."/includes/config.php", "w"); @fwrite ($fp, "<?php\n\$config_user = " . var_export($config, true) . ";\n?>"); @fclose ($fp); 

Then I try to connect:

 require $_SERVER['DOCUMENT_ROOT']."/includes/config.php"; 

It does not work, it gives out old data that was before fwrite . On another hosting there are no problems, everything works. Tell me what's wrong?

  • one
    Remove @ before functions and see what error it gives out - Semushin Sergey
  • It does not issue errors, writes to the file correctly - 15828
  • That is, error screening does not work, but without screening, everything became normal? - Semushin Sergey
  • not written to the file and written correctly, but require reads old data that was before fwrite - 15828

1 answer 1

After line

 @fclose ($fp); 

add

 if (function_exists('opcache_invalidate')) opcache_invalidate($_SERVER['DOCUMENT_ROOT']."/includes/config.php", true); elseif (function_exists('apc_delete_file')) @apc_delete_file($_SERVER['DOCUMENT_ROOT']."/includes/config.php"); 

so that the APC and OPcache update correctly passed. Although maybe you have another caster / accelerator worth :)

  • thanks, it worked. Maybe in the settings of php to prescribe something that was like everyone else? - 15828
  • maybe there is some kind of universal solution? - 15828
  • @ 15828, issue a class / method / function at the input to which you give the desired array, the file name, and he / she saves the file and “fights” the cache. More probably neither, since different caches / accelerators can stand on different machines or not stand at all. PS Or use a ready-made class (with github) for data caching. - Visman