Skip to content

Commit

Permalink
Add built-in server script to example sites #32
Browse files Browse the repository at this point in the history
  • Loading branch information
tanakahisateru committed Jun 5, 2012
1 parent a6fca76 commit 4255443
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions empty-projects/prod/_app/server
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
host="localhost:8801"
if [ $# -ge 1 ]; then
host=$1
fi
php -S ${host} -t ../ `dirname $0`/server.php

23 changes: 23 additions & 0 deletions empty-projects/prod/_app/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
$req = preg_split('/\?/', $_SERVER['REQUEST_URI']);
$path = array_shift($req);
$param = implode('?', $req);
$reqfile = $_SERVER['DOCUMENT_ROOT'] . $path;
$is_html = preg_match('/(\.html?|\.php)$/', $reqfile); // like as .htaccess
if($is_html || !is_file($reqfile)) {
$_SERVER['PATH_INFO'] = $path;
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . '/_gateway.php';
$_SERVER['SCRIPT_NAME'] = '/_gateway.php';
$_SERVER['PHP_SELF'] = '/_gateway.php' . $path;
chdir($_SERVER['DOCUMENT_ROOT']);
require $_SERVER['DOCUMENT_ROOT'] . '/_gateway.php';
// To display log in CLI use stderr
$stderr = fopen('php://stderr', 'w');
fprintf($stderr, "[%s] %s:%d [???]: %s\n",
@strftime('%c'), $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'],
$_SERVER['REQUEST_URI']
);
}
else {
return false;
}

0 comments on commit 4255443

Please sign in to comment.