Install failed - realpath relative path issue?

ee

Joined: 2004-12-20
Posts: 7
Posted: Mon, 2004-12-20 23:54

When I get to step 2 in the install process, I receive the following warning and error:

Quote:
Warning: checkmanifest(/modules/core/classes/GalleryUtilities.class): failed to open stream: No such file or directory in steps/SystemChecksStep.class on line 237

Fatal error: checkmanifest(): Failed opening required '/modules/core/classes/GalleryUtilities.class' (include_path='') in steps/SystemChecksStep.class on line 237

Figuring that there's a problem with the relative path calculation, I added code to echo dirname(__FILE__), realpath(dirname(__FILE_)) and a stack trace just before the calculation of $base on line 235. Here's the output

Quote:
dirname(__FILE__)=steps
realpath(dirname(__FILE__))=
Array
(
[0] => Array
(
[file] => steps/SystemChecksStep.class
[line] => 198
[function] => checkmanifest
[class] => systemchecksstep
[type] => ::
)

[1] => Array
(
[file] => /home/www/eeaston/gallery2/install/index.php
[line] => 159
[function] => loadtemplatedata
[class] => systemchecksstep
[type] => ->
)

)

Now I don't know much about php, but it looks like a problem calculating the relative path having something to do with the way that realpath works. I also know that on my host, gallery2 really is located either at

Quote:
/home/www/eeaston/gallery2

or

Quote:
/www/eeaston/gallery2

. When I log in I get a symlink from /home/eeaston/www to /www/eeaston. So in short I don't know what the real mount point for gallery2 is compared to what realpath is returning, but I suspect something odd here.

I installed it just fine on a private freebsd box, so the build I grabbed is okay. It just doesn't seem to handle the path setup that my hosting provider is using (cihost).

Any ideas?

Evan
----

Gallery URL (optional):http://www.eeaston.com/gallery2/install/index.php?step=2
Gallery version: v2 - 2004-12-20 nightly
Webserver (with version):Apache 1.3.31
PHP version (eg 4.2.1): 4.3.9
phpinfo URL (optional): http://www.eeaston.com/phpinfo.php
Graphics Toolkit(s): NetPBM
Operating system: Redhat 6.
Web browser/version:

Quote:
 
fryfrog

Joined: 2002-10-30
Posts: 3236
Posted: Tue, 2004-12-21 00:35

I think that almost all paths in gallery should be absolute, and from the output in your first error it looks like they are relative. I would try it with the two paths you pasted above and see what happens. Of course, maybe this error is popping up even though you are using the absolute path?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-12-21 02:06

php docs say __FILE__ is

Quote:
The full path and filename of the file. If used inside an include, the name of the included file is returned.

This is ambiguous what path info, if any, for an included file is returned.. to me it sounds like filename only but it appears you get a relative path and filename and I (and most php's, mine is 4.3.8 on freebsd) get an absolute path to the included file. try putting print __FILE__; in install/index.php and install/steps/SystemChecksStep.class .. what do you get for each? maybe you can get your install to proceed by changing $base to '../' instead of that realpath call... but you might get other problems later from this.

 
ee

Joined: 2004-12-20
Posts: 7
Posted: Tue, 2004-12-21 04:11

For install/index.php

Quote:
__FILE__=/home/www/eeaston/gallery2/install/index.php

And for install/steps/SystemChecksStep.class

Quote:
__FILE__=steps/SystemChecksStep.class
realpath(__FILE__)=

I'm able to get past the issue with the failure in the require_once call by hacking this code, but then all sorts of other things fail later.

Is my php built wrong? Is there a php.ini var I can set to tailor the behavior? Or does gallery2 need to be improved, to say derive the root dir from the top level php page instead of from __FILE__, in order to be more robust?
Evan

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-12-21 06:47

yeah, i expected as much.. we use dirname(__FILE__) a lot... it seems like your php is misbehaving, as i've not seen this before.. but as i mentioned before the php doc is a bit ambiguous so maybe we shouldn't be counting on a full path.. bharat, any insight on this one?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Wed, 2004-12-22 04:52

Oy. The check in the installer is supposed to detect this and let you know right away! Turns out that it wasn't sophisticated enough (I was looking for "steps/SystemChecksStep.class"). I've improved it so on the next nightly, it should give you a big warning right away.

This looks like PHP bug 13936. I don't know what causes it, and though they claim to have fixed it, it keeps popping back up again. That's why we put this check in the installer. Evan, can you add your info to that bug so that we can help them to narrow down and fix it?

Unfortunately, it's going to be really difficult for you to patch or work around this issue. We rely heavily on this at a very low level and even if you get by some of the initial issues with it, you're going to be hitting it everywhere. The problem with it is that __FILE__ is a magic token in PHP that can't be easily simulated or abstracted out (which is why our error handling code has it liberally sprinkled all over the place). There are 6500+ references to it in gallery2! So we can't replace it with a function .. the best we could do is to try to wrap it but even then we need to know the directory that we're currently in in order to figure out what to prepend to it. For example, in SystemChecksStep.class it gets back "steps/SystemChecksStep.class" so it has to know to prepend /home/www/eeaston/gallery2/install, which only the requiring/including file knows. If we could narrow this down to only includes or requires, you could probably do some magic to store the state in a global whenever you do a require (but even that will get hairy)...

 
ee

Joined: 2004-12-20
Posts: 7
Posted: Thu, 2004-12-23 03:41

Yep. I'll update the bug with my information. I guess I'll have to bug my hosting provider to see if they can update the version of php. Maybe this is the impetus I need to seek out a new hosting provider and get onto newer OS and supporting tools. Thanks for the help.

 
ee

Joined: 2004-12-20
Posts: 7
Posted: Sun, 2004-12-26 04:41

FYI, it seems that there is a pretty reliable way to change the gallery2 code to cope with this bug. But it would mean changing all include and require usages to look like:

include(dirname(__FILE__)."/includedfile");

If this were done everywhere, then the included files can get the realpath to __FILE__. This demonstrates the issue on my server http://www.eeaston.com/phpbug13936/ (excuse my php). And the interesting thing about it is that it intermittently reports

Quote:
__FILE__=./includes/included.php

for the first of the three include calls instead of

Quote:
__FILE__=includes/included.php

I only mention this as I have little hope that
a) there will be anything remotely like a fix for the version of php installed on my host, and
b) my hosting provider is currently unwilling to do anything to try and help me work through the problem
So short of switching hosting providers, which I may just do, I'd love to see the gallery2 code fixed to cope with my crappy hosting provider ;-). Of course, ensuring that you can consistently use special galleryInclude and galleryRequire functions instead of what php provides would be troublesome at best and thus not really address my selfish wants.

Evan

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sat, 2005-01-01 22:47

Hmm. We use the include format that you suggest pretty much everywhere in the code already so if your theory is correct, then it should be working for you. (Grep around for uses of include and require and see if we missed any).

I fixed a couple of spots in the installer and upgrader where we didn't do this. But everywhere else I'm pretty sure that we do. We have to, otherwise embedding G2 won't work quite properly.

 
ee

Joined: 2004-12-20
Posts: 7
Posted: Sat, 2005-01-08 17:45

So I bothered to mess around with it some more. In the file, install/index.php (using alpha 4) I changed the lines 70 and 163 from:

070: require("steps/$className.class");
163: include('templates/MainPage.html');

to:

070: require(dirname(__FILE__)."/steps/$className.class");
163: include(dirname(__FILE__).'/templates/MainPage.html');

and was indeed able to get through the install. So it does seem that if you did a complete search/replace everywhere my host would be happy and so would I.

I'll pull nightlies sometime and see if anything else is still broken for me.
Evan

 
dogunderdog

Joined: 2006-01-25
Posts: 1
Posted: Wed, 2006-01-25 16:25

Hi,
what happened to this thread, is the suggested way a possible workaround? and if so, why is it not yet fixed everywhere in gallery?

cheers,
Florian

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2006-01-26 23:50

nothing happened.
if __FILE__ doesn't work in your php, it means your php is buggy. we can't do anything about it.