Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91327 invoked from network); 11 Jul 2011 15:09:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2011 15:09:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=ava3ar@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ava3ar@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: ava3ar@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:44352] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/82-09103-E021B1E4 for ; Mon, 11 Jul 2011 11:09:04 -0400 Received: by vwl1 with SMTP id 1so817470vwl.29 for ; Mon, 11 Jul 2011 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=LQx25qGvpMPfdPfy8ogS96BRDgQXRDT9OluT1cGHcwA=; b=TiG1h81BHQIsj1GTv2zjmKB372HwFlLU7WQP8zLC5zYQdt17U1rSVthew2GioHVPly +zbVyCX95mg32yJDUwE7VeuZ1sYErijVU8lZJK4eFx7V5E8uBY8ANafXTqBEr+kZonBn 1gHbordOUntl/n1SG64gelXYBwMvz2v177I4g= Received: by 10.220.29.138 with SMTP id q10mr1287399vcc.13.1310396939139; Mon, 11 Jul 2011 08:08:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.72.68 with HTTP; Mon, 11 Jul 2011 08:08:39 -0700 (PDT) In-Reply-To: References: <4E1B0579.8000307@smashlabs.com> Date: Mon, 11 Jul 2011 16:08:39 +0100 Message-ID: To: Kiall Mac Innes Cc: Ralph Schindler , internals@lists.php.net Content-Type: multipart/alternative; boundary=485b395e72bf12792404a7cc90cb Subject: Re: [PHP-DEV] Built-in web server routing script and static assets From: ava3ar@gmail.com (Keloran) --485b395e72bf12792404a7cc90cb Content-Type: text/plain; charset=ISO-8859-1 it does seem silly that the server would even try to serve those files rather than check if they are of a certain header/mime before, but at least with this method it does mean that you can "fix" your code to always bypass this, and if your purposlly testing through the CLI-server anyway, changing your code to "work" isnt that much a problem (imo) On Mon, Jul 11, 2011 at 3:39 PM, Kiall Mac Innes wrote: > Hi Ralph, > > I'm aware of the ability to use a routing script to determine which files > to > serve via a "return false;". > > My concern is that every framework / application etc is going to need one > in > order to work with the built-in server (even if they all need the same > one!).. > > So considering this functionality is required by most (if not all) front > controller based applications and frameworks, and considering the router > script is really only useful for front controller based applications and > frameworks, why is this not the default behavior? > > It seems silly to make use of the built-in server rely on more boilerplate > code than we already have in our apps! > > Maybe this just feels weird because its PHP, rather than an apache/nginx > config file .. > > I'm probably still be missing something though :) > > Thanks, > Kiall > > > On Mon, Jul 11, 2011 at 3:15 PM, Ralph Schindler >wrote: > > > Hey Kiall, > > > > An optional argument to the built in web server can be a php based > router. > > If the router returns false, it will attempt to return the resource > > as-it-is on disk. > > > > Your command line looks like this: > > > > php -S localhost:8000 -t ./path/to/docroot routing.php > > > > routing.php can be one of two things- either a drop in replacement for > > .htaccess or your sites index.php. > > > > My routing.php looks like this: > > > > > > > // OR if (preg_match('/\.(?:png|jpg|**jpeg|gif)$/', > > $_SERVER["REQUEST_URI"])) > > if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) { > > return false; // serve the requested resource as-is. > > } else { > > include_once 'index.php'; > > } > > > > > > If you choose to put your index.php in as the router, then your index.php > > should be cli-server aware: > > > > > > > if (php_sapi_name() == 'cli-server') { > > /* route static assets and return false */ > > } > > > > /* go on with normal index.php operations */ > > > > > > I like the former approach as the routing.php can go inside your version > > control ignore list and won't get checked in as part of the project. > > > > To me, that is as many lines of Apache rewrite that one would have had > and > > it is as feature complete as Apache rewrite. > > > > -ralph > > > > > > > > On 7/11/11 6:46 AM, Kiall Mac Innes wrote: > > > >> Hiya, > >> > >> I've been playing with the built-in server, and have some concerns over > >> how > >> static assets are handled. > >> > >> Currently, to run an application on the built-in server, we essentially > >> need > >> to list out all the static assets that should be served directly from > >> disk. > >> This is the opposite of what I believe the most common web server > >> configurations use. > >> > >> I believe the built-in server should mimic typical configurations, > rather > >> than requiring applications to write code solely for PHP's web server. > >> > >> Have I just missed something? or if not, what do people think of how > >> static > >> files are handled currently? > >> > >> A typical Apache config extract (IMHO): > >> > >> # Turn on URL rewriting > >> RewriteEngine On > >> RewriteBase / > >> > >> # Allow any files or directories that exist to be displayed directly > >> RewriteCond %{REQUEST_FILENAME} !-f > >> RewriteCond %{REQUEST_FILENAME} !-d > >> > >> # Rewrite all other URLs to index.php/URL > >> RewriteRule .* index.php/$0 [PT] > >> > >> Apologies is this has been brought up before, I've not seen any > discussion > >> of this topic so far. > >> > >> Thanks, > >> Kiall > >> > >> > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --485b395e72bf12792404a7cc90cb--