|
Posted by ZeldorBlat on 05/18/07 18:02
On May 18, 1:54 pm, purcaholic <purcaho...@googlemail.com> wrote:
> On 18 Mai, 18:51, "Steve" <no....@example.com> wrote:
>
>
>
> > i'm trying to re-use scripts, typically called via a browser, in the php
> > cli. the cli calls are made through cron jobs. i'm hitting some unknowns as
> > to path info. here's the error i'm getting thus far:
>
> > "PHP Warning: require_once(../../../../../../site.cfg.php): failed to open
> > stream: No such file or directory in
> > /var/www/html/dev/admin/cli/import.repair.orders.cli.php on line 5"
>
> > i'm executing the cli from:
>
> > /home/me/www/dev/admin (www is a symlink to /var/www/html/)
>
> > first, what is the current directory for php cli when executed from a cron?
> > second, will i need to adjust the current directory or anything else so that
> > other included/required files (normally accessed via a browser) are
> > referenced correctly?
>
> > thanks for your input.
>
> > =======================
>
> > here's the pertanent code...
>
> > my include path is:
>
> > /usr/share/pear
>
> > in that directory i have a file named relative.path.php. its purpose is to
> > abstract/simplify inclusionary script paths. it looks like:
>
> > <?
> > $parsedUri = dirname($_SERVER['PHP_SELF']);
> > $parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
> > $relativeUri = str_replace('/', '', $parsedUri);
> > $relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
> > if ($relativePath < 0){ $relativePath = 0; }
> > $relativePath = str_repeat('../', $relativePath);
> > if (!$relativePath){ $relativePath = './'; }
> > ?>
>
> > i'm wrapping the files i'm trying to re-use via cli in code similar to (call
> > it, import.financials.cli.php):
>
> > #!/usr/bin/php -q
> > <?
> > $cli = true;
> > require_once 'relative.path.php';
> > require_once $relativePath . 'site.cfg.php';
> > require_once site::$rootDirectory . 'admin/import.financials.php';
> > ?>
>
> > the site.cfg.php creates a singleton class 'site' and $rootDirectory would
> > be the absolute path to the web root. import.financials.php begins like
> > this:
>
> > <?
> > if (!$cli)
> > {
> > $pageTitle = 'Import Financials';
> > $fullHeader = false;
> > $securityEnabled = true;
> > require_once 'relative.path.php';
> > require_once $relativePath . 'site.cfg.php';
> > require_once site::$includeDirectory . 'head.inc.php';}
>
> > ?>
>
> > however, as the error indicated, we never get to this point since
> > import.financials.cli.php cannot find site.cfg.php (as it normally would if
> > called from a browser).
>
> > tia,
>
> > me
>
> Hi Steve,
>
> the superglobal $_SERVER exists only, if PHP is running as a module or
> cgi (webserver). Use __FILE__ instead of $_SERVER['PHP_SELF'].
> Or you can put a workaround in your cli wrapper, by setting
> $_SERVER['PHP_SELF'] or other needed $_SERVER[*] variables.
>
> purcaholic
I beg to differ. Running print_r($_SERVER) from the CLI outputs all
sorts of stuff -- including PHP_SELF.
[Back to original message]
|