[kronolith] Re: Free/busy (once again!)

Graeme Fowler graeme at graemef.net
Mon Mar 21 14:31:02 PST 2005


On Mon 21 Mar 2005 19:52:52 GMT , Graeme Fowler <graeme at graemef.net> wrote:
> It appears that this is something to do with my Apache/PHP install - which is
> PHP running as a CGI, with Horde as the document root.

Yep. When run as a module, the PATH_INFO and associated env vars don't 
exist, as
they're only created when PHP runs as a CGI (assuming I'm reading things
correctly). There are differences, too, in the way things are handled between
Apache 1.3 (which I have) and Apache 2, but they're irrelevant here.

I think that this is a bug in a very specific set of cases, namely when PHP
scripts are being parsed via an AddHandler/Action pairing, either in 
the Apache
config file or in a .htaccess. This is the case for me:

# .htaccess for new Horde installation
# must run PHP via CGI API in order to not break
# other vhosts which still need older PHP...
Options +ExecCGI
AddHandler php-script .php
AddHandler php-script .php3
AddHandler php-script .php4
Action php-script /phpbin/php.cgi
DirectoryIndex index.php
# EOF .htaccess

Where I've followed the TFM posted in a number of places, including 
PHP.net, in
order to install as a CGI and parse everything through the CGI interpreter as
above.

The gotcha, for me, is that this means the following - if I call a simple "<?
phpinfo() ?>" page which lives in the document root, ie. the /horde top-level
directory:

_ENV["SCRIPT_FILENAME"]	/home/user1/localbin/phpbin/php.cgi
_ENV["QUERY_STRING"]	c=user1
_ENV["REQUEST_URI"]	/php_user1_info.php?c=user1
_ENV["SCRIPT_NAME"]	/phpbin/php.cgi
_ENV["PATH_INFO"]	/php_user1_info.php
_ENV["PATH_TRANSLATED"]	/home/user1/localbin/horde/php_user1_info.php

Because we're eventually calling /phpbin/php.cgi to run the script, the
PATH_INFO env var contains the actual script name and *not* any other trailing
data - and because it's set, it ends up with invalid data in it. So the code
snippet from fb.php:

> // Determine the username to show free/busy time for.
> if (!empty($_SERVER['PATH_INFO'])) {
>    $cal = basename($_SERVER['PATH_INFO']);
> } else {
>    $cal = Util::getFormData('c');
>    if (is_array($cal)) {
>        $cal = implode('|', $cal);
>    }
> }

...ends up with invalid data as explained earlier, and we get no 
free/busy data
back again. It looks to me like we need either to flip the logic around,or use
something other than the PATH_INFO variable to get the correct query data.

If I flip the logic, it works:

// Determine the username to show free/busy time for.
if ($cal = Util::getFormData('c')) {
    if (is_array($cal)) {
        $cal = implode('|', $cal);
  }
} else {
     $cal = basename($_SERVER['PATH_INFO']);
}

Alternatively, as there's an overhead doing it that way, we could 
revert to the
original check but use QUERY_STRING instead of PATH_INFO, and process that:

// Determine the username to show free/busy time for.
if (!empty($_SERVER['QUERY_STRING'])) {
    $cal = str_replace("c=","",$_SERVER['QUERY_STRING']);
} else {
    $cal = Util::getFormData('c');
    if (is_array($cal)) {
        $cal = implode('|', $cal);
    }
}

They both work, and they should both work just as well for the module 
version of
PHP as the CGI version. If someone (Chuck?) explains the motives behind the
original code, I'll shut up and do something else instead!

I'd enter another bug... but that's up for discussion this time instead :)

Graeme



More information about the kronolith mailing list