[PHP-users 34417] Re: Include ファイルの相対パスと絶対パスについて

take t.takeyoshi @ gmail.com
2009年 3月 12日 (木) 12:01:10 JST


平岡さん、こんにちは。
takeです。

is_readable("../lib/global.func");
ではどうでしょうか?

実は私も同じような現象に遭遇し調査したことがあります。
PHPのVersionは 5.1系でした。
相対パスで指定されたファイルについて、is_readableではtrueなのに、includeは失敗していました。

調べたら、どうやらバグのようでした。
http://bugs.php.net/bug.php?id=41822

------
ここからはご参考までに、私のケースでの解決策です。

結論から申しますと、全て絶対パスでの呼び出しに変更しました。

といってもリリース時にステージングとオンラインの環境差異をあっちこっち変更反映するのは面倒かつ怖いので
頻繁に呼び出すファイル群を設置しているディレクトリをinclude_pathに通しちゃいました。

今回のケースなら

/home/USER/public_html/DIR/lib

をinclude_pathに追加して


スクリプト側では

include("global.func");

とした感じです。


2009/03/12 10:53 Seiichirou Hiraoka <flathill @ netspring.co.jp>:
> 平岡と申します。
>
> Solaris10 SPARC 上で PHP 5.2.4 を使用しております。
> 先日、PHP の再コンパイル (GD 及び XML モジュールを追加) を
> 行った所、自作の PHP スクリプト中で Include していたものが
> 相対パスではなく絶対パスでないと失敗する (Internal Server
> Error) ようになりました。
>
> 尚、PHP のバージョン及び php.ini の変更は行っておりません。
> また、PHP を以前のバージョンに戻す (再インストール) 事で、
> 問題が発生しなくなることも確認しております。
>
> 問題発生前後のコンパイル方法は以下の通りです。
> # AAA 及び BBB は PREFIX です。
>
> o 発生前 (継続的に利用できていた)
>  ./configure  --prefix=/AAA --with-config-file-path=/AAA/lib/php \
>    --enable-memory-limit \
>    --disable-ipv6 --with-iconv-dir=/BBB \
>    --with-gettext=/BBB/share/gettext --with-openssl=/BBB \
>    --with-imap=/src/mail/c-client/imap-2006j \
>    --with-imap-ssl=/AAA --with-zlib \
>    --with-apxs2=/AAA/apache/bin/apxs \
>    --with-pgsql=/AAA/pgsql --with-mysql=/AAA/mysql \
>    --with-mysqli=/AAA/mysql/bin/mysql_config \
>    --enable-mbstring --enable-mbregex --with-ldap=/BBB
>
> o 発生後 (再コンパイル後)
>  ./configure  --prefix=/AAA --with-config-file-path=/AAA/lib/php \
>    --enable-memory-limit \
>    --disable-ipv6 --with-iconv-dir=/BBB \
>    --with-pgsql=/AAA/pgsql --with-mysql=/AAA/mysql \
>    --with-mysqli=/AAA/mysql/bin/mysql_config --enable-mbstring \
>    --enable-mbregex --with-ldap=/BBB \
>    --with-gettext=/BBB/share/gettext --with-openssl=/BBB \
>    --with-imap=/src/mail/c-client/imap-2006j--with-imap-ssl=/AAA \
>    --with-zlib --with-apxs2=/AAA/apache/bin/apxs --with-gd=/BBB \
>    --with-xsl --with-freetype-dir=/BBB --enable-gd-native-ttf \
>    --enable-gd-jis-conv
>
> 今回 PHP に追加した GD, XML, FreeType のバージョンは以下の通りです。
>    gd-2.0.35, libxml2-2.6.30, freetype-2.3.8
>
> 実際に問題が発生したスクリプトは、ユーザの public_html 配下に
> 置かれており、該当箇所は以下の通りです。
>
> include("../lib/global.func");
>
> これを以下のように修正することで、問題が発生しなくなりました。
>
> include("/home/USER/public_html/DIR/lib/global.func");
>
> 問題が発生したときには、以下のような PHP のログが出力されており
> ました。
>
> [12-Mar-2009 08:39:30] PHP Warning:  include(../lib/global.func) [<a href='function.include'>function.include</a>]: failed to open stream: Permission denied in /home/USER/public_html/DIR/index.php on line 17
> [12-Mar-2009 08:39:30] PHP Warning:  include() [<a href='function.include'>function.include</a>]: Failed opening '../lib/global.func' for inclusion (include_path='.:/AAA/lib/php') in /home/USER/public_html/DIR/index.php on line 17
> [12-Mar-2009 08:39:30] PHP Fatal error:  Call to undefined function printheader() in /home/USER/public_html/DIR/index.php on line 285
>
> index.php の 17 行目に include が書かれており、それが Permission
> Denied で読み込まれなかったために、 285 行目でエラーになっており
> ます。
>
> このことから、相対パスでの Include が出来なくなっていると思われ
> ますが、php.ini や PHP の設定は変更しておりません。どなたか、
> アドバイスを頂けませんでしょうか。
>
> php.ini の変更箇所は以下の通りです。
>
> % diff -ruN php.ini.ORG php.ini | grep ^\+
> +++ php.ini     2009-03-11 18:08:22.908251000 +0900
> +display_errors = Off
> +display_startup_errors = On
> +log_errors = On
> +error_log = /tmp/php_error.log
> +post_max_size = 10M
> +extension_dir = "/AAA/lib/php/extensions"
> +upload_max_filesize = 10M
> +mbstring.http_output = EUC-JP
> +mbstring.encoding_translation = On
> +mbstring.detect_order = ASCII,JIS,EUC-JP,SJIS,UTF-8
>
> その他必要な情報等ございましたら御連絡下さい。
> 以上、よろしくお願い致します。
>
> - flathill
> _______________________________________________
> PHP-users mailing list  PHP-users @ php.gr.jp
> http://ml.php.gr.jp/mailman/listinfo/php-users
> PHP初心者のためのページ - 質問する前にはこちらをお読みください
> http://oldwww.php.gr.jp/php/novice.php3
>


PHP-users メーリングリストの案内