php - Include file twice with opcache -


i'm trying understand why opcache_reset doesn't reset cache stated in documentation. if include file, modify file, call opcache_reset, include same file, still uses cache though cache supposed reset "the next time hit".

this function resets entire opcode cache. after calling opcache_reset(), scripts reloaded , reparsed next time hit.

  1. obviously understanding of "the next time hit" not same php's implementation. should amended state "the next time hit after request"?
  2. through trial , error discovered opcache_invalidate works if it's called before opcache_reset. implies 2 linked though opcache_invalidate documentation not reference opcache_reset. why opcache_reset cause opcache_invalidate not function designed if opcache_reset called before opcache_invalidate? note: logically, 2 mutally exclusive , should need call 1 or other, not both.
  3. the second answer so question states opcache.enable php_ini_all , can disabled ini_set. true not find references opcache in list of php.ini directives. if opcache included php 5.5.0 , later, why aren't corresponding php ini directives documented? see question 4.
  4. actually, opcache runtime configuration page lists php.ini settings. determines if settings listed in list of php.ini directives page vs other page? apc , memcache directives listed not opcache directives.

here's example script. if second include not cached, timestamp after second include match timestamp in file contents.

<?php $timestamp = ''; $filename = './phptest-contents.php';  echo "php version: " . phpversion() . "<br/>";  // include file first time include($filename); echo "timestamp after first include: $timestamp<br/>";  // generate different contents //sleep(2); $date = (new datetime())->format('y-m-d h:i:s'); $contents = <<<eot <?php \$timestamp = '{$date}';  eot;  $handle = fopen($filename, 'w'); fwrite($handle, $contents); fclose($handle);  // file contents see on disk $contents = file_get_contents($filename); echo "file contents: <pre>" . htmlspecialchars($contents) . "</pre><br/>";  // disable opcache // works , timestamps match //ini_set('opcache.enable', 0);  // try invalidate or reset opcache included file // reset before invalidate not work // invalidate before reset works expected if (opcache_is_script_cached($filename)) {     echo "before opcache_reset: opcache caching $filename<br/>"; } if (opcache_reset()) {     echo "opcache reset<br/>"; } if (opcache_invalidate($filename, true)) {     echo "opcache invalidated $filename<br/>"; } if (opcache_is_script_cached($filename)) {     echo "after opcache_reset: opcache caching $filename<br/>"; }  echo "opcache status:<br/>"; echo "<pre>"; print_r(opcache_get_status()); echo "</pre>";  // include file second time include($filename); echo "timestamp after second include: $timestamp<br/>"; 

i'm running php 5.6.27 apache 2.4.23.

n.b.: please ignore glaring security issues; above script meant demonstrate problem, not secure.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -