Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45361 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43074 invoked from network); 24 Aug 2009 21:46:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2009 21:46:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=ezyang@MIT.EDU; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ezyang@MIT.EDU; sender-id=pass Received-SPF: pass (pb1.pair.com: domain MIT.EDU designates 18.7.7.80 as permitted sender) X-PHP-List-Original-Sender: ezyang@MIT.EDU X-Host-Fingerprint: 18.7.7.80 BISCAYNE-ONE-STATION.MIT.EDU Solaris 9 Received: from [18.7.7.80] ([18.7.7.80:53086] helo=biscayne-one-station.mit.edu) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/17-03363-D3A039A4 for ; Mon, 24 Aug 2009 17:46:38 -0400 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by biscayne-one-station.mit.edu (8.13.6/8.9.2) with ESMTP id n7OLkYPn012795 for ; Mon, 24 Aug 2009 17:46:34 -0400 (EDT) Received: from localhost (ita4fw1.itasoftware.com [63.107.91.99]) (authenticated bits=0) (User authenticated as ezyang@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id n7OLkX21015301 for ; Mon, 24 Aug 2009 17:46:34 -0400 (EDT) Content-Type: text/plain; charset=UTF-8 To: internals Date: Mon, 24 Aug 2009 17:46:33 -0400 Message-ID: <1251149348-sup-4709@javelin> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.42 X-Spam-Flag: NO X-Spam-Score: 0.00 Subject: Per-directory PHP configuration From: ezyang@MIT.EDU ("Edward Z. Yang") Hello all, I cooked up a patch that gives PHP support for per-directory php.ini files that properly inherit. This makes php.ini files act a little like .htaccess files. We are cognizant of the associated performance issues, and thus this is a strictly optional feature. For a little history, the current, common approach is to set PHPRC to be the current directory, so that a php.ini file from that directory is read. This unfortunately also overloads the global php.ini file, has an odd ordering with respect to php.d, and means that you have to place a php.ini file/symlink in every directory where PHP scripts could be run. While the patch is no where near where I would be comfortable formally submitting it for review on internals, I'd like to gauge how friendly the core PHP developers would be to an enhancement like this. In a nutshell, here is how the patch works: In php_ini.c, php_init_config() is patched to call php_user_init_config() if user directory php.ini's are accepted. The function then: 1. Retrieves the current working directory 2. Checks if the cwd is inside the user's home directory 3. Successively walks up from the user's home directory to the cwd, checking if a php.ini exists and loading it with zend_parse_ini_file if it does. We also have two special cases of behavior that we found helpful for our use-case: * We serve only a user's ~/web_scripts directory, so perform an optional check to make sure the PHP file is in the right place, and to not attempt to load ~/php.ini * If we had Apache frob $HOME such that it points to a "different" home directory, which is the web serve directory, skip the previous check. To get an idea for its behaviors, take the following example: /etc/php.ini foo = 1 bar = 1 /mit/user/web_scripts/wiki/php.ini foo = 2 Then, we see the following behavior for the following PHP scripts /mit/user/web_scripts/test.php foo = 1 bar = 1 /mit/user/web_scripts/wiki/test.php foo = 2 bar = 1 /mit/user/web_scripts/wiki/subdir/test.php foo = 2 bar = 1 I am looking forward to your comments, and I can post the very rough (but functional) patch if you are so interested. Cheers, Edward