Jump to content

Developing, I must keep deleting the assets/cache/FileCompiler folder


Xonox
 Share

Recommended Posts

Hi,

On some of the sites that I develop, I must keep deleting assets/cache/FileCompiler folder in order to see the  changes made in the php files. I have cache disabled for the template, but it doesn't seem matter. As you might imagine, this extra step is costly in dev time.

Usually this happens in just some pages and not in other. Am I missing something?

Thanks,

Link to comment
Share on other sites

Try loggin in as superadmin while developing, though I am almost 100% sure that FileCompiler always checks for new versions of files. Are you getting anything at the FileCompiler log? Setup > Logs > FileCompiler

Link to comment
Share on other sites

Is opcode caching active on those sites (opcache, APC)? If yes, one of those could be responsible. If the site used opcache, make sure that opcache.validate_timestamps is true, for APC make sure that apc.stat is enabled.

  • Like 1
Link to comment
Share on other sites

36 minutes ago, elabx said:

Try loggin in as superadmin while developing, though I am almost 100% sure that FileCompiler always checks for new versions of files. Are you getting anything at the FileCompiler log? Setup > Logs > FileCompiler

Tried this, but it doesn't make a difference!

Link to comment
Share on other sites

49 minutes ago, elabx said:

Are you getting anything at the FileCompiler log? Setup > Logs > FileCompiler

The changed file doesn't appear as compiled in the logs.

After I delete the FileCompiler folder, the template is updated, but the file still doesn't show as compiled in the logs.

However, the file is inside the FileCompiler folder.

If the file is in the folder, shouldn't it show in the logs?

Link to comment
Share on other sites

@Xonox You can disable compilation for template files while developing using

// /site/config.php

// disable template compilation when debug mode is active
// or set false to disable compilation completely
$config->templateCompile = !$config->debug;

 

Link to comment
Share on other sites

4 minutes ago, abdus said:

You can disable compilation for template files while developing using

When I do that, I get a Fatal Error. Can't use:

$pages = wire('pages');

Fatal error: Call to undefined function wire()

Link to comment
Share on other sites

6 minutes ago, Xonox said:

Call to undefined function wire()

This error occurs if you dont have namespace declared inside the file. Try putting <?php namespace ProcessWire; to the first line. 

Edit: You should add namespace to all template files to prevent the errors when compilation is disabled.
This is actually FileCompiler's purpose, refreshing the page once is often enough to recompile files, but I am not sure why it's not working for you.

  • Like 1
Link to comment
Share on other sites

@Xonox have you used template caching at all?  I really don't use template caching on any of my sites except one, which is the only one i have seen the same problem.  May be unrelated, it happens even after I turned all the template caching off.  

Adding the namespace didn't seem to help for me.

I also have a bunch of files in the templates folder that don't render as visible templates (basically reusable chunks) so I think that makes them less likely to get checked/recompiled (they just get included in actual rendered templates).

Haven't gotten to the bottom of it and it's a site that rarely gets dev changes so I just delete the compiled versions whenever anything is changed in those template files and it's fine.  Haven't tried re-installing and frankly for my affected site it's not worth the effort, but would be interested if anyone finds a solution or explanation.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 5/2/2017 at 1:53 PM, Loges said:

I also have a bunch of files in the templates folder that don't render as visible templates (basically reusable chunks) so I think that makes them less likely to get checked/recompiled (they just get included in actual rendered templates).

I also develop like that. I noticed that when I copy the changes to the production server, there's no need to delete the cache. So I'm figuring that it must be some configuration. I haven't had the time to compare both dev and the production servers. If I get to any conclusion, I'll post it.

Link to comment
Share on other sites

  • 6 months later...

I've just come across this issue whilst debugging a bug on our site.

It seems strange as it's only happening when I try to debug 1 particular php file, but not others. I'm getting the error

Compile Error: Cannot redeclare getTopUrls() (previously declared in /xxxx/xxxx/site/templates/php/lib/Lib.php:12) (line 57 of /xxxx/xxxx/site/assets/cache/FileCompiler/site/templates/php/lib/Lib.php)

I've tried adding @abdus ' suggestion to no avail.

On 29/04/2017 at 2:19 AM, abdus said:

@Xonox You can disable compilation for template files while developing using


// /site/config.php

// disable template compilation when debug mode is active
// or set false to disable compilation completely
$config->templateCompile = !$config->debug;

 

How can I stop the FileCompiler from compiling?

Update :
1) I've realised it's not a template file it's compiling, it's a library file with common functions that is referenced by many other modules. Other modules that reference this lib file can be compiled & debugged fine.
2) I've tried to change from require_once to include_once with no effect.

Update 2:
3) I've tried setting the filecompileroptions in config but it didn't work. Perhaps I set it incorrectly?

$config->fileCompilerOptions = array(
    'siteOnly' => false,  // only allow compilation of files in /site/ directory
    'showNotices' => true, // show notices about compiled files to superuser when logged in
    'logNotices' => true, // log notices about compiled files and maintenance to file-compiler.txt log.
    'chmodFile' => '', // mode to use for created files, i.e. "0644"
    'chmodDir' => '',  // mode to use for created directories, i.e. "0755"
    'exclusions' => array('lib','Lib','/../lib','lib.php','Lib.php'), // exclude filenames or paths that start with any of these
    'extensions' => array('php', 'module', 'inc'), // file extensions we compile
    'cachePath' => $config->paths->cache . 'FileCompiler/', // path where compiled files are stored
);

Update 3:

Changed all require_once  to include_once (extended the scope of change)
Tried Installing PW 3.0.84 (latest dev) but didn't work.

Edited by FrancisChung
Security. Removed sensitive URL sections
Link to comment
Share on other sites

After struggling with this for a few days, I've managed to fix it find a hack for it.

Basically, I had to turn on debug on in config.php, go through the dependency chain of my classes and functions.
I will outline some of the strategies I used but your mileage will probably vary depending on your particular situation. 

In my situation, this was only happening if I'm trying to generate a PDF file which is a very specific use case.
Again to reiterate, I was not getting this issue with my other use cases.

 

1) Consolidate / Reduce your dependency tree into something smaller. 

   That meant instead of creating an object from a class and calling a method on it, I imported the function as a whole to the calling class

2) Importing functions from a common library/classes and removing references to them. Luckily, there was only 1 function to duplicate. 

3) Change all require/include calls to require_once -> include_once 

4) You can try using class_exists function as a last resort, only if you're sure you've cleaned up your call chain. I just couldn't work out why it was trying to load these 2 classes twice, so I used class_exists and that was the last error I fixed before I got it to work.

I had tried to use class_exist with other classes in my earlier attempts and it was just propagating the issue down the call chain. This is the hack I'm really not comfortable with, but whatever works right now I will take it.
 

if (!class_exists("\Site\Logo"))
    include_once("Logo.php");

if (!class_exists("\Site\KeywordParser"))
    include_once("KeywordParser.php");

 

P/S How I got into this mess in the first place is because I have a class template that automatically does a include_once to my Library PHP file that has commonly reused functions

Edited by FrancisChung
Correction + P/S
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...