CLI include paths to run zend framework via cron

Posted by summerg on Stack Overflow See other posts from Stack Overflow or by summerg
Published on 2010-04-27T17:00:02Z Indexed on 2010/04/27 17:13 UTC
Read the original article Hit count: 296

I wrote a command line utility using Zend Framework to do some nightly reporting. It uses a ton of the same functionality the accompanying site. It works great when I run it by hand, but when I run it on cron I have include path issues. Seems like it should be easily fixed with set_include_path, but maybe I'm missing something?

My directory structure looks like this:

/var/www/clientname/
    application
        Globals.php
    commandline
        commandline_bootstrap.php       
    public_html
        public_bootstrap.php        
    library
        Zend

In public_bootstrap.php I use set_include_path without a problem, relative to the current directory:

set_include_path('../library' . PATH_SEPARATOR . get_include_path());  

If I understand correctly, in commandline_bootstrap.php I need to put in the absolute path, so cron knows where everything is. My file starts like this:

error_reporting(E_ALL);
set_include_path('/var/www/clientname/library' . PATH_SEPARATOR . get_include_path());  
require_once "../application/Globals.php";

But when I run it via cron I get the following error:

PHP Fatal error: require_once(): Failed opening required '../application/Globals.php' (include_path='/var/www/clientname/library/') in /var/www/clientname/commandline/zfcli.php on line 11

I think PHP is accepting my new path, because when I run it command line and dump the phpinfo I can see:

include_path => /var/www/clientname/library/:.:/usr/share/pear:/usr/share/php => .:/usr/share/pear:/usr/share/php

I admit the syntax here looks a little strange, but I can’t figure out how to fix it. Any suggestions would be greatly appreciated.

Thanks summer

© Stack Overflow or respective owner

Related posts about php

Related posts about cron