Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53872 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83105 invoked from network); 11 Jul 2011 14:39:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2011 14:39:45 -0000 Authentication-Results: pb1.pair.com header.from=kiall@managedit.ie; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kiall@managedit.ie; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain managedit.ie designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: kiall@managedit.ie X-Host-Fingerprint: 209.85.215.42 mail-ew0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:40359] helo=mail-ew0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/11-09103-C2B0B1E4 for ; Mon, 11 Jul 2011 10:39:43 -0400 Received: by ewy2 with SMTP id 2so1319768ewy.29 for ; Mon, 11 Jul 2011 07:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=managedit.ie; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=HZ1XJp0122SuC+PN7sRHyPIv6Q04/QPieAhDXOsC/uk=; b=VtmXgJsnFrng1fBE7RJDQiEE2/Yk0lInvPwSIRgnrhxaowEnMw8z/zHyiew68Gznau ILhjBFGHYKLnJuvT7A/9lNsMmLvwXng9G+0bgA8kmo5Vi3PJpq5Wcp8ksORZaZblr4qy 3GDE9P28nl+8c4QEBuRJoHhMKWLyVhnQzVAkg= Received: by 10.14.16.4 with SMTP id g4mr1440038eeg.240.1310395175337; Mon, 11 Jul 2011 07:39:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.14.95.206 with HTTP; Mon, 11 Jul 2011 07:39:15 -0700 (PDT) In-Reply-To: <4E1B0579.8000307@smashlabs.com> References: <4E1B0579.8000307@smashlabs.com> Date: Mon, 11 Jul 2011 15:39:15 +0100 Message-ID: To: Ralph Schindler Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016e6594accf0fea504a7cc261d Subject: Re: [PHP-DEV] Built-in web server routing script and static assets From: kiall@managedit.ie (Kiall Mac Innes) --0016e6594accf0fea504a7cc261d Content-Type: text/plain; charset=ISO-8859-1 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 > > --0016e6594accf0fea504a7cc261d--