Skip to content

Commit

Permalink
NEW: Added support for PHP 5.4's built-in webserver.
Browse files Browse the repository at this point in the history
PHP 5.4 comes with a built-in webserver.  This addition to main.php adds support for it.  It is designed to be run like so:

php -S localhost:3000 framework/main.php

The router will pass access of any file back to the built-in webserver, and handle all other URLs.
  • Loading branch information
Sam Minnee committed Sep 10, 2012
1 parent 5bf2212 commit 1005571
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions main.php
Expand Up @@ -63,8 +63,22 @@
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
}

// PHP 5.4's built-in webserver uses this
if (php_sapi_name() == 'cli-server') {
$url = $_SERVER['REQUEST_URI'];

// Querystring args need to be explicitly parsed
if(strpos($url,'?') !== false) {
list($url, $query) = explode('?',$url,2);
parse_str($query, $_GET);
if ($_GET) $_REQUEST = array_merge((array)$_REQUEST, (array)$_GET);
}

// Pass back to the webserver for files that exist
if(file_exists(BASE_PATH . $url)) return false;

// Apache rewrite rules use this
if (isset($_GET['url'])) {
} else if (isset($_GET['url'])) {
$url = $_GET['url'];
// IIS includes get variables in url
$i = strpos($url, '?');
Expand Down Expand Up @@ -109,4 +123,4 @@

// Direct away - this is the "main" function, that hands control to the appropriate controller
DataModel::set_inst(new DataModel());
Director::direct($url, DataModel::inst());
Director::direct($url, DataModel::inst());

2 comments on commit 1005571

@sminnee
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chillu or @hafriedlander - FrozenFire has asked for this in the 3.0 branch. Seems pretty safe to me; any concern?

@chillu
Copy link
Member

@chillu chillu commented on 1005571 Apr 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.