LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-05-2007, 10:25 AM   #1
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
php include path puzzle


Hello folks,
In the php.ini I have
Code:
include_path=".:/usr/php/includes:/usr/php/includes/pear:/usr/php/includes/classes"
In the /usr/php/includes/classes directory I have
Code:
[root@localhost classes]# ls -l
total 44
drwxr-xr-x 3 root root  4096 2007-10-05 20:46 ckt
-rw-r--r-- 1 root root 28910 2007-10-05 17:23 class.validator.php
[root@localhost classes]#
And in the /usr/php/includes/classes/ckt directory I have
Code:
[root@localhost ckt]# ls -l
total 32
-rw-r--r-- 1 root root 5901 2007-10-05 20:46 class_ckt.php
-rw-r--r-- 1 root root 5901 2007-10-05 20:46 class_ckt.php~
[root@localhost ckt]#
Now in my php script if I have
Code:
require_once 'ckt/class_ckt.php';
The script works.
But if I try to include the "class.validator.php" file the script fails and blanks out.
Code:
require_once 'class.validator.php';
require_once 'ckt/class_ckt.php';
I am not able to understand the reason for this seemingly strange behaviour because this "class.validator.php" resides in the same directory as the "ckt" directory.

Can any one enlighten me.
IN addition, It may seem odd that I have three directories each having "/usr/php/includes" in the php.ini as indicated above. I felt that I could include all the required files with relative path like require_once 'pear/MDB2.php'. But I found that too did not work out.
puzzling !
Guide me.
Thanks in advance.



Prabhat Soni

Last edited by prabhatsoni; 10-05-2007 at 10:34 AM.
 
Old 10-06-2007, 08:08 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
What directory is this PHP script running in? What is the full absolute path to the script?
 
Old 10-06-2007, 09:52 PM   #3
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Thanks for taking time to help me,

The php script is running in /var/www/html/.

This is really strange. One file in a directory is getting included and the other is not. Certainly there should be a reason here.

Now I have created validator directory at the same level as the ckt, and put this validator class in this new direcory. So the scenario is like this:
include_path=/usr/php/includes/classes
and the two files I am trying to include are
"/usr/php/includes/classes/ckt/ckt_class.php" and
"/usr/php/incldes/classes/validator/class.validator.php"
by writing in the script
"require_once 'ckt/ckt_class.php" and
"require_once 'validator/class.validator/php"
respectively.
The first one is getting included and the other one is not.

Please help.

Thanks once again.


Prabhat Soni

Last edited by prabhatsoni; 10-06-2007 at 09:53 PM.
 
Old 10-06-2007, 10:43 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
I agree. At a glance, it appears to make no sense :/
Have you checked that both folders in the include_path have similar read permissions, and that the script has sufficient permissions to access both folders?

Also, what happens if you specify the full path? Like:
require_once "/usr/php/incldes/classes/validator/class.validator.php"

or even:

require_once "../../../usr/php/incldes/classes/validator/class.validator.php"

which seems ridiculous, but depending on exactly how the server is configured and what if any open_basedir() restrictions are in place, I have seen it necessary, though this would/should affect both folders equally, so it is again rather odd..


Will it do it either of these ways? If it does, then there's something wrong with the way the server is interpreting the relative path you're using.

I don't know if I can be of much help, but will try if something comes to me. My PHP is somewhat rusty, and it has been a while since I have played with it in a production environment.
 
Old 10-07-2007, 12:16 AM   #5
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
They have exactly same permissions and ownerships - the file as well as the folders.
Going a step further, I have moved this class.validator.php into the ckt directory. Now the ckt directory has two files one is the "ckt_class.php" and the other is "class.validator.php". Now I try to include two files and again I find that once is included and the other in not.

Then I tried to include it with the full path. Again I drew blank. It therefore impies that there is something very wrong with the class.validator.php. This was downloaded from internet. SO what I did is deleted the contents of the file and kept only the opening and closing php-tags. Now find that the script is not blanking out. So there is some syntax problem in the file. I will check the file out.
Thanks for giving me the idea about using the full path.


Prabhat Soni.
 
Old 10-07-2007, 07:23 AM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Just a thought, but where you are using 'require_once' is there a chance that the file has ALREADY been included? Therefore it is being skipped the second time around?
Check whether the FIRST file you 'require_once' contains an include statement which is including the second file ..
If the second file (the one that is NOT being included properly) isn't humungous, you *could* post it for us, though that is very weird the way this appears
 
Old 10-08-2007, 10:02 PM   #7
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Just O had guessed.
The validator class that I downloaded from webmasters had an error in one of its class methods. I commented that out and I don;t have any problem.

But there is something which I wanted to clarify.

But first the directory structure:

From php.ini

include_path="usr/php/includes/"

Follolwing are the directories in /usr/php/includes:
/usr/php/includes/pear
/usr/php/includes/classess

The "classess" contains:
/usr/php/includes/classes/ckt

The "ckt" contains:
/usr/php/includes/classess/ckt/class_ckt.php

Now this class_ckt.php uses the pear class. How should I include this.
I tried to use it as
require_once 'pear/MDB2.php'
(Thinking that it will be evaluated with respect to the include_path)
But it failed.
Then I used
require_once './../../pear/MDB2.php'
(thinking that it will be evaluated with respect to the current directory of the class_ckt.php, i.e., ckt)
This too failed.

What is the recommended way for this.


Thanks


Prabhat Soni
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using PHP & MySQL to make a small web puzzle; help? Jorophose Programming 15 06-20-2007 08:38 PM
php include path khilari Linux - Newbie 1 05-31-2006 11:53 AM
where did my include path go aot2002 Linux - Wireless Networking 2 01-24-2004 05:02 AM
Path to include? Mazen Alzogbi Red Hat 1 11-15-2003 06:25 AM
PHP Path include ..:eMa:.. Programming 4 09-25-2003 01:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration