-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add built-in server script to example sites #32
- Loading branch information
1 parent
a6fca76
commit 4255443
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |