Failed to load Zend/Loader.php. Trying to work out why? - php

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.

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.

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.

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

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.

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.

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();
}
...

Related

Specific project PHP files returning blank pages

So, I have this project uploaded at webwire.in/alpha , but it's returning blank pages.
PHP Fatal error: require(): Failed opening required './classes/Cookie.php' (include_path='.:/usr/share/php:/usr/share/pear in /var/www/html/alpha/core/init.php on line 22
and one on line 25.
Line 21-23 code = spl_autoload_register(function($class) {
require_once ('./classes/' . $class . '.php'); //line 22
});
Line 25 = require_once ('./functions/sanitize.php');
Tricky thing about this error is that this works only for this alpha folder. It was occurring yesterday also but somehow got fixed. Now when I deleted the files and uploaded, the error is back. Yesterday, at least the alpha/admin was working, but today nothing is working in this alpha folder.
One more thing, I've uploaded the same file to a different server, and it works flawlessly. See here - crowdsourced.in/rationshop (shared hosting)
Current server is a VPS if that matters.
I am not expert here, still tried solutions as I searched, but none worked for me till now.
Any help is highly appreciated.
Pages included are included relative to the page that was loaded, not the script doing the include.
So, if you have a script in the folder: /var/www/html/alpha/admin/
And that includes the script: /var/www/html/alpha/core/init.php
And init.php includes the file ./functions/sanitize.php
Then init.php is looking relative to the folder /var/www/html/alpha/admin/ which is where the initial script was loaded. Not looking relative to the init.php script. It is looking for a file at: /var/www/html/alpha/admin/functions/sanitize.php which doesn't exist. I'm assuming it exists under /var/www/html/alpha/core/functions/sanitize.php.
The easy fix is to use __DIR__ which is a built in php magic constant that has the value of the current script (the currently included file). Inside of /var/www/html/alpha/core/init.php, __DIR__ == /var/www/html/alpha/core/. So you can include/require __DIR__."/functions/sanitize.php

what's wrong with my require_once path?

I've switched my files over from a local environment to my vps and now my facebook notification isn't working even thought I'm pretty sure I've updated all the paths correctly. I've tried writing the require path numerous ways.
I'm doing a "$.post" from jquery to a php page where the facebook notification is sent and am getting this error:
<b>Fatal error</b>: Class 'Facebook' not found in
<b>/home/zjkkvcxc/public_html/accepted.php</b> on line <b>9</b><br />
//THIS IS MY PHP REQUIRE PATH.
require_once('php-sdk/facebook.php') ;
//IN MY LOCAL ENVIRONMENT I WAS USING THIS PATH BECAUSE IT WAS THE ONLY ONE THAT WORKED. THIS DOESN'T WORK ON MY VPS THOUGH.
require_once(dirname(__FILE__).'/php-sdk/facebook.php') ;
You use require_once and have error "Class 'Facebook' not found". If you tried require_once on a file that does not exist, it would cause other error: "Fatal error: require(): Failed opening required 'php-sdk/facebook.php'". So the path is probably OK. Check if you uploaded php-sdk properly. The facebook.php might be empty.
Your error is :
Fatal error</b>: Class 'Facebook' not found in
<b>/home/zjkkvcxc/public_html/accepted.php</b> on line <b>9
The valuable information here is :
the error occurred because the Facebook class is unknown which means that require_once did not pop this error
the error occurred on line 9 of accepted.php
Now you have to look why the class Facebook is unknown on line 9.
if you have included the facebook.php before line 9 it is probably not containing the right class. (class names are case sensitive!)
if you include facebook.php after line 9 you just have to call it earlier.
PS: posting the first 10-15 lines of accepted.php might give us enough information to pinpoint the exact problem here.
I have faced issues like this before, and the best way to handle this is to set your true filepath as a variable & prepend that to your includes/requires. Becuase the whole dirname(__FILE__) setup can act oddly in different environments especially those that use symbolic links. Explicitly stating where files are to be set is the best solution.
So let’s assume this is your codebase path; as per your example:
/home/zjkkvcxc/public_html/
Set that as a variable that all of your pages load in some way like this:
$BASE_PATH = '/home/zjkkvcxc/public_html/';
And now when you make calls to the file system for your app, do this:
require_once($BASE_PATH . 'php-sdk/facebook.php');
What is nice about a setup like this is that you can make your app portable between environments by just changing $BASE_PATH to match your local environment. Like this might be a path for a MAMP (Mac OS X LAMP) setup:
$BASE_PATH = '/Application/MAMP/htdocs/';
Regarding how odd __FILE__ can act in symlinked environments, read up here:
Since PHP 4.0.2, _ FILE _ always contains an absolute path with
symlinks resolved whereas in older versions it contained relative path
under some circumstances.
Class not found error not refers to problem loading file. You are using a require , if file not exists a require error will be raised and this is not the case.
Probably the class inside facebook.php is not called Facebook, probably is with another name or with other case like "facebook"
Fatal error</b>: Class 'Facebook' not found in
<b>/home/zjkkvcxc/public_html/accepted.php</b> on line <b>9
Is it possible that:
your short_open_tag is enabled on your local environment and
it's disabled on your vps and
you are using <?instead of <?php in your facebook.php file
For some odd reason, i encounter circumstances where php doesn't find the file i need through conventional means. i found some code used for searching a directory and retrieving a list of files, which was advantageous in a url generation script i was writing. overtime, i have used this simple script for many tasks, such as finding files when normal require/include fails. in a pinch, this hack works for me.
Just fill in the file name $somefile and directory name $log_directory if your directory is in the base path just type it with no slashes. if its below the base path type it like this /path/to/folder
hope this helps.
$somefile = '<!--Filename You need to find-->';
$log_directory = '<!--Directory you want to search-->';
$results_array = array();
if (is_dir($log_directory))
{
if ($handle = opendir($log_directory))
{
while(($file = readdir($handle)) !== FALSE)
{
$results_array[] = $file;
}
closedir($handle);
}
}
foreach($results_array as $value)
{
if ($value == $somefile) {
$url_include = $log_directory."/".$value;
}else{
die("error file not found.");
}
}
require_once("$url_include");
require_once JPATH_SITE.'/php-sdk/facebook.php';
The require path you said is wrong:
require_once('php-sdk/facebook.php') ;
This need there has a file got full pathname: /dir/to/your/actual/include/path/php-sdk/facebook.php
And later you require file in include_path wrong, dirname(__FILE__) OR __DIR__ is directory of the file where require_once() is called, so you are looking for facebook.php in php-sdk sub-directory under you current php script.
To fix your problem, you have 2 plan
Better one, find your actual include_path and put php-sdk files in, include_path can find from php.ini, or run php -m from shell, or phpinfo(), in this way, your first require_once() will work.
Make sure php-sdk directory includes facebook.php is in same parent directory with your calling php script, this is not common usage, but will make your second require_once() work.
I suggest you to study more on php include_path configure and __FILE__ magic constant.
define('DOC_ROOT', realpath(dirname(__FILE__) . '/'));
require_once(DOC_ROOT . '/php-sdk/facebook.php');
Assuming the folder php-sdk is at the root of you website directory.
require_once('php-sdk/facebook.php') ;
This assumes that the facebook.php file is in a folder that resides in the current folder of the PHP file beind called.
Is this the case? I suspect not since you have an error!
Are you in a folder up from the root?
---ROOT
---ROOT > FOO --your script here?
---ROOT > php-sdk --facebook in here
If so...
require_once('../php-sdk/facebook.php');
would work.
Try $_SERVER['DOCUMENT_ROOT'].'/path to /php-sdk/facebook.php'
$_SERVER['DOCUMENT_ROOT'] will give absolute path for www or htdocs folder then you can provide path to facebook.php

php include with wamp

I'm developing a site on my local wamp stack. I have created an alias to view the site so i go to localhost/eee/ to view it. Ideally i would like to go to www.eee.lo but ever since upgrading to win8 I can't get it to work.
So this is the problem, i'm making modules for the website so i don't have to change all the code etc... And i don't want to have to go around changing all the url's when i migrate to the online server so i'm creating a file called _control.php which has this;
$_SITELOC = "localhost/eee/";
And then each time i want to include a file i will go;
include "$_SITELOC/scripts/inc/_header.php";
But this doesn't work and i can't work out why as if i echo it rather than include it and then i take what it prints and put it into the url it goes to the correct file. But it throws errors on the include, it gives two warnins;
Warning: include(localhost/eee/scripts/inc/_header.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in C:\Users\Chris\Documents\EEE\Website\Site\index.php on line 3
Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'localhost/eee/scripts/inc/_header.php' for inclusion (include_path='.;C:\php\pear') in C:\Users\Chris\Documents\EEE\Website\Site\index.php on line 3
I read somewhere that it might be to do with the include path so i tried;
set_include_path(get_include_path() . PATH_SEPARATOR . $_SITELOC."/scripts/inc/");
but this too did not work and now i'm not sure where to go.
Thanks, Chris
localhost/eee/ is your public address that you can use in your web browser. This public address should more appropriately be written as http://localhost/eee/. When you move to web server, you get the public address http://www.eee.lo/.
When including files, you have to use file paths. For example, if you have your www (or httpd, whatever) directry in D:\ on windows, then your include path should start with D:\www\eee\.
So, basically you have to use two variables to keep paths.
$_SITELOC = "http://localhost/eee/"; //For all URLs used in your HTML document.
$_INCPATH = "D:\www\eee\\"; //For all internal file includes.
In practice, you will need both of these, and it is good practice to keep the website address and internal paths out of your main script because when uploaded to remote server, not only your public address changes, but you will also have to deal with absolutely different internal (include) paths.
Your idea is basically good, to define one (root) path of the application and include files based on it, but unfortunately you're not doing it quite right. You have basically two ways of doing that.
One way (which I personally find better) is to include local files in your file system, where you can define the root path, i.e. like
define ('ROOT', 'your/document/root/path');
// and then include the files
include ROOT . '/' . '/scripts/inc/_header.php';
The other way would be to include a web resource, what you're trying to do, but you've forgotten to specify the scheme (protocol) you want to use, i.e.
define ('ROOT', 'http://localhost/eee');
// and then include the files
include ROOT . '/' . '/scripts/inc/_header.php';
For more information, see the examples, provided by the documentation for include
Note: If you want to include the source of a php file, i.e. file with definitions of functions, etc., use the first approach. Including files, using the second approach will only include the output produced by that file.
If you include() a URL, you will (probably) be including the output of the script's execution, when you want to include the script's source. It seems like you actually want to include by local file system path.

Require_once PHP Error

I've been programming in PHP for several years now and never encountered this error before.
Here's my widget.php file:
require_once('fruit.php');
echo "I am compiling just fine!!!";
And my fruit.php file:
$bVar = true;
When these two files look like this ^ then everything compiles with no errors and I get the "I am compiling just fine!!!" success message.
Now, the minute I move the fruit.php file one directory level up, and change my widget.php file to reflect the directory restructuring:
require_once('../fruit.php');
echo "I am compiling just fine!!!";
Now all the sudden, I get PHP warnings & fatal errors:
Warning: require_once(../fruit.php) [function.require-once]: failed to open stream: No such file or directory in /webroot/app/widget.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../fruit.php' (include_path='.:/usr/local/php5/lib/php') in /webroot/app/widget.php on line 1
In all my years working with PHP, I've never seen require_once() fail like this before. Any ideas?!?!
Maybe you are in the wrong work directory. Its a bad idea to rely on it (except you explictly want to access it) anyway. Use
require __DIR__ . '/../fruit.php';
or with pre-5.3
require dirname(__FILE__) . '/../fruit.php';
Remind, that paths starting with .., or . are not resolved against the include-path, but only against the current work directory.
Remember that in the second case, you're specifying a path, but in the first case it uses your includes path. Perhaps rather than explicitly specifying .. in the second case, you case modify your include path.
http://php.net/manual/en/function.set-include-path.php
I know the question is old, but it is still relevant.
In my experience, the "open_basedir" directive is most likely to cause this issue.
require_once('fruit.php');
This searches for fruit.php in the same directory as widget.php is in, no matter what the current working directory is.
require_once('../fruit.php');
This searches for fruit.php in a directory above the current directory, not in the directory above the one widget.php is in.

include an php file with included files

Here is directory structure
/global.php
/includes/class_bootstrap.php
/includes/init.php
/plugins/myplugin.php
Here is codes in these files
/start.php
require('./includes/class_bootstrap.php');
/includes/class_bootstrap.php
define('CWD', (($getcwd = getcwd()) ? $getcwd : '.'));
require_once(CWD . '/includes/init.php');
/plugins/myplugin.php
require_once(dirname(__FILE__).'../global.php');
And as far as I am understanding the problem is in class_bootstrap.php file coz it's generating wrong path for CWD
here is error:
Warning: require_once(C:/wamp/www/vb4/plugins/includes/init.php) [function.require-once]:
failed to open stream: No such file or directory in C:/wamp/www/vb4/global.php on line 35
As you can see "C:/wamp/www/vb4/plugins/includes/init.php" is wrong path.
The MAIN PROBLEM is that I can edit only myplugin.php file other files are CMS core files and should not be changed.
How can I fix this issue?
If you need to determine the base path of a set of scripts, you should not rely on the "current working directory." This can change from executing environment to executing environment.
Instead, base it on a known path.
/includes/class_bootstrap.php knows that it's going to be one directory down from where the base path is going to be, so it can do this:
define('CWD', realpath(dirname(__FILE__) . '/../') );
dirname gets the directory name given in the passed string. If __FILE__ returns C:/wamp/www/vb4/plugins/includes/class_bootstrap.php, then dirname will return C:/wamp/www/vb4/plugins/includes. We then append /../ to it and then call realpath, which turns that relative .. into a real directory: C:/wamp/www/vb4/plugins
Phew.
From that point forward, CWD will operate as you expect. You can require_once CWD . '/includes/init.php' and it will correctly resolve to C:/wamp/www/vb4/plugins/includes/init.php
Also, this may sound stupid but "vb4" may be referring to vBulletin 4, in which case your plugin may already have access to the configuration information that it exposes, including handy things like paths. This may make this entire exercise unnecessary. I intentionally know nothing about vB, otherwise I would point you at their dev docs.

Categories