I have the following file structure:
cron.php
/includes/functions.php
/classes/ClassName.php
corn.php includes functions.php calls new ClassName(). And functions.php contains the primitive autoloader:
function __autoload($class_name) {
require_once('classes/'.$class_name.'.php');
}
which works fine when cron.php is called from browser. However if run from shell it is giving “No such file or directory” fatal error. I tried to wrap ‘classes/’.$class_name.’.php’ into realpath() function to no avail. Please advise.
You may use
dirname(__FILE__)to get the “absolute” current directory of your autoloading PHP script.You could do something like (supposing your autoloading script is in a subdirectory of your project):
See: