ghost files or apache cacheing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bobboau
Forum Newbie
Posts: 2
Joined: Tue Sep 29, 2009 3:01 pm

ghost files or apache cacheing

Post by bobboau »

:banghead:
ok, so it seems as though passing a relative path to require or require_once is causing an old version of a file to be loaded. even if I go so far as to rename the directory make a new one with the same name and move the old fies one by one into the new file as I get the errors of them missing, the file in question still loads the old version, even without the new version present.

specific situation:

my webroot is in /var/www/

my project is in /var/www/poolparty/

if I load a file for testing an interface

/var/www/poolparty/SearchResultsSessions.php

which includes a library file

require_once "lib/SearchResultsSessions.php";

i.e. loading the file:
/var/www/poolparty/lib/SearchResultsSessions.php

that file includes several other files that are in the same directory, for example:
require_once 'userManagement.php';

in userManagement.php a new function was added
function user_get($user_id = NULL){...}

in a function in /var/www/poolparty/lib/SearchResultsSessions.php that function is called with nothing passed.

the result I get from the script is

Code: Select all

Fatal error: Call to undefined function user_get() in /var/www/poolparty/lib/SearchResultsSessions.php on line 50
if I change the statement in SearchResultsSessions.php to an absolute path,
require_once '/var/www/poolparty/lib/userManagement.php'; everything works fine

what the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> is happening? this happened with another file and I solved the problem by modifying the file with nano as a superuser when the file shouldn't have been there.

I'm developing on a kubuntu 9.4 laptop useing the latest versions of aphache and php in the repositories.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: ghost files or apache cacheing

Post by requinix »

Paths given to include() and require() are relative to the current working directory - not the directory of the file being executed. Sometimes they may be the same, sometimes they may not be.

Use absolute file paths. For something in the current file's directory you can use

Code: Select all

require_once dirname(__FILE__) . '/userManagement.php';
bobboau
Forum Newbie
Posts: 2
Joined: Tue Sep 29, 2009 3:01 pm

Re: ghost files or apache cacheing

Post by bobboau »

so, it would be relative to the main file's directory? (assuming the working directory gets set to the directory of the file called by the web client)

that doesn't explain why it's loading an old version of the file, it should be giving me some sort of 'can't find file' error.
and it also doesn't explain why most files are getting included just fine.
Post Reply