2
votes

I have inherited a client site which crashes every 3 or 4 days. It is built using the zend-framework with which I have no knowledge.

The following code:

<?php
    // Make sure classes are in the include path.
   ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'classes');

    // Use autoload so include or require statements are not needed.
    require_once 'Zend/Loader.php';
    Zend_Loader::registerAutoload();

    // Run the application.
    App_Main::run('production');

Is causing the following error:

[Tue Sep 02 12:58:45 2008] [error] [client 78.***.***.32] PHP Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in /srv/www/vhosts/example.co.uk/httpdocs/bootstrap.php on line 6 
[Tue Sep 02 12:58:45 2008] [error] [client 78.***.***.32] PHP Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='.:.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/vhosts/example.co.uk/httpdocs/bootstrap.php on line 6 

I don't even know where to begin trying to fix this. My level of knowledge of PHP is intermediate but like I said, I have no experience with Zend. Also, contacting the original developer is not an option.

The interesting thing is that even though the code is run every time a page of the site is hit the error is only happening every now and then.

I believe it must be something to do with the include_path but I am not sure.

6

6 Answers

3
votes

for a start I think your include path should maybe have a trailing slash. Here is an example of mine :

    set_include_path('../library/ZendFramework-1.5.2/library/:../application/classes/:../application/classes/excpetions/:../application/forms/'); 

You bootstrap file will be included by another file (probably an index.php file). This means that if your include path is relative (as mine is) instead of absolute, then the path at which Loader.php is looked for changes if the file including bootstrap.php changes.

For example, I have two index.php files in my Zend app, one for the front end, and one for the admin area. These index files each need there own bootstrap.php with different relative paths in because they are included by different index files, which means they have to be relative to the original requested index file, not the bootstrap file they are defined within.

This could explain why your problem is intermittent, there could be another file including the bootstrap somewhere that is only used occasionally. I'd search through all the sites files for 'bootstrap.php' and see all the places which are including / requiring this file.

1
votes

The fact that it only happens sporadically makes me think this is less of a programming issue, and more of a sysadmin issue - if it were a defect in the implementation, you'd expect it to fail consistently considering the error is "No such file or directory". Two guesses

  • There are multiple front-end web servers, and one of them is mis-configured (missing the Zend Framework).

  • The PEAR include directory is network mounted, and occasionally vanishes for short periods of time.

It could be a more insidious file system problem, but one would think this would effect more than just one file.

1
votes

I had the same problem, but problem was in permissons to files. I gave chmod for all RWX and now is everything fine.

So maybe someone else will have same problem as me, then this was solution.

Regards

0
votes

It works sometimes so there isn't anything inherently wrong on the PHP end of things (if the path was wrong it would never work... but it does, yes?). So what is causing Loader.php to be periodically inaccessible? I would suspect a permissions problem. Something that is making Loader.php or the directory that it is in inaccessible. Maybe a cron job is setting/reseting permissions? Check that first. See what permissions are when it is working and what they are when it is not.

0
votes

In my case the Zend/Loader.php was not in the PEAR-directory. It should be there, but my webserver was a little raw. But you can insert it in the library/Zend directory as well.

But indeed this does not answer why your problem occurs only sometimes.

0
votes

I had this error as well when I was working with PHPUnit 3.5.5. My main application script loaded the zend framework fine, however the test class ran into errors.

My solution was to add the following to the test class

   ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'classes');

    require_once 'ThemeWidgets.php';
    require_once 'PHPUnit/Framework.php';

    require_once '../../library/Zend/Loader/AutoLoader.php';


    class ThemeWidgetsTest extends PHPUnit_Framework_TestCase
    {

        public function setUp() {
            Zend_Loader_Autoloader::getInstance();
        }
...