2

We are building several applications around one Codeigniter installation (v2.0.3). We began development in a Windows environment (using XAMPP), and deployed our alpha installation to a virtual CentOS 5.6 machine (which works perfectly). As the project progressed, I began to need access to video tools (ffmpeg/mencoder) that are (practically) unavailable on Windows. I have been using a virtual installation of CentOS 5.7 (running in VirtualBox 3.2.8) to develop other applications, so I installed the software on that virtual CentOS. We had added several libraries to the "Codeigniter/system/libraries" folder so that they are available to all of the different applications. On my local virtual CentOS, our core libraries will not load, we receive an error message saying the classes do not exist. The paths exist, and we can readfile their contents, and include_once does not throw an error... they just won't work.

We tracked down the inclusion of the core libraries, and found that our lib was being loaded in "system/core/Loader.php" on line 886 via an "include_once". After much tweaking, we determined that if we changed that "include_once" to an "include", the file was included, and the entire software suite worked exactly as expected (exactly as it does on the other systems).

What... the... heck? Do we need to enable "include_once" somewhere in PHP's config? The path is obviously correct, since the "include" works. I just don't have any desire to go changing the system core of CI if it's not completely necessary.

Any input (or even reasonable speculation) would be appreciated. Cheers.

6
  • Generally libraries should only ever be loaded one, hence the requirement for using include_once. This is to prevent unintended behavior such as class re-declaration. Commented Nov 16, 2011 at 18:36
  • Are you calling a custom include_once() on the library class before loading it via CI's method? Commented Nov 16, 2011 at 18:37
  • We're trying to load everything through CI so I am never calling "include" or "include_once" myself. And even if I were, the class would at least exist (and probably throw a "re-declaration" error, as @john-cartwright suggests). In my case, the error message generated by CI is "Non-existent class". Commented Nov 16, 2011 at 18:58
  • error message "Non-existent class" occurred because "include_once" didn't include anything. It means that libraries already included by CI or yourself. Commented Nov 16, 2011 at 19:04
  • 2
    That's really odd. I would expect errors the other way. I've had some issues with CI's includes before, but they always had to do with filename capitalization differences between host systems. Other than that, I'm tempted to label this a bug. Commented Nov 17, 2011 at 2:20

3 Answers 3

1

First of all check if you have php-apc installed. if you have it, edit the apc.ini (it should be /etc/php.d/apc.ini on CentOS), and disable the include_once optimization:

apc.include_once_override=0 

it may deliver very odd results with CodeIgniter, as for example not finding libraries or helpers...

restart your web server:

service httpd restart

and now it should be ok. :)

Sign up to request clarification or add additional context in comments.

1 Comment

Sir or Madam, you have given me the most helpful advice so far, and for that I thank you. But unfortunately, I do not have APC installed :( Thank you for your answer regardless, hopefully it will help someone.
0

Answer by the asker:

We have at least determined that this seems to be related to our version of PHP. Our old systems that worked were on PHP 5.3.3. The newer one (that does not work) is on PHP 5.3.4. We pulled back the version to 5.3.3, and suddenly the "include_once"s in CodeIgniter magically started working. How's about them apples? We're calling it a PHP bug for now, and we're going to try to reproduce it for the benefit of all mankind (or at least anyone else who finds this problem).

Comments

0

Temporary fix :

add FCPATH with the application folder name.

        define('APPPATH', FCPATH.$application_folder.'/');

add this to the application path :

// The path to the "application" folder
    if (is_dir($application_folder))
    {
        define('APPPATH', FCPATH.$application_folder.'/');
    }
    else
    {
        if ( ! is_dir(BASEPATH.$application_folder.'/'))
        {
            exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
        }

        define('APPPATH', BASEPATH.$application_folder.'/');
    }

Hope this helps Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.