Note that there are some explanatory texts on larger screens.

plurals
  1. POphp - Is php caching classes before creation?
    text
    copied!<h1>Background Information:</h1> <p>I'm using <a href="http://symfony.com/doc/current/components/console/introduction.html" rel="nofollow">Symfony Console Component</a> to write a console application that is wrapped into a <a href="http://api.symfony.com/2.4/Symfony/Component/Console/Shell.html" rel="nofollow"><code>Shell</code></a> object. I wrote a command named <code>console:reload</code> that empties the array of commands from the <code>Application</code> object, and re-adds commands classes listed under certain directory.</p> <p>This command is run when the shell starts, so, the <code>Application</code> is loaded with the available commands. The classes being loaded are located in a special directory and should follow a simple name rule: <code>&lt;CommandName&gt;Command.php</code>:</p> <pre><code>// Inside ReloadCommand-&gt;execute() method... $pamperoApp = $this-&gt;getApplication(); $pamperoApp-&gt;clearCommands(); $namespace = "pampero\\cli\\modules"; foreach(glob(MODULES_DIR . "/*/*Command.php") as $command) { $class = str_replace(".php", "", $namespace . "\\" . basename(dirname($command)) . "\\" . basename($command)); $this-&gt;getApplication()-&gt;add(new $class); } </code></pre> <p>The autoload provided by Symfony (Composer?) <code>ClassLoader</code> is used:</p> <pre><code>// Main entry point... loader = require_once __DIR__ . '/../vendor/autoload.php'; $loader-&gt;set('pampero', __DIR__ . '/../..'); </code></pre> <p>I read the code from <code>ClassLoader</code> class and what it does is to store file name path, so no object caching there.</p> <h1>Here's the problem:</h1> <p>I launch the app: <code>php packages.php</code>. The shell appears after <code>ReloadCommand</code> command being executed. A list of available and loaded commands are ready to be used.</p> <p>If I create a new file, let's say: <code>ExampleCommand.php</code>, and then I type: <code>console:reload</code>, the new command will indeed be added. Now, If I modify the code inside <code>ExampleCommand.php</code> and run <code>console:reload</code> again, the changes made to the class won't take effect.</p> <p>But that's not all. If I remove the example file, call <code>console:reload</code>, create the file again and run: <code>console:reload</code> the command will be added.</p> <h1>Reading:</h1> <p>I have read APC related things, and before creating new classes I have done things like:</p> <pre><code>// Prior adding commands in ReloadCommand apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); </code></pre> <p>Without luck. I've also run <code>apc.php</code> and enabled/disabled <code>apc.enable_cli</code> option. None of those things creates the object represented by the modified file.</p> <p>So my hints and clues about the problems turns to be classes caching when a file/class is found. But how to avoid that for this special case? I don't want to restart the shell if some extra funcionality is added through classes.</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload