Skip to content

Instantly share code, notes, and snippets.

@okayawright
Created March 28, 2019 15:36
Show Gist options
  • Save okayawright/c0eb8a61045a5a145734e8d45e18a47b to your computer and use it in GitHub Desktop.
Save okayawright/c0eb8a61045a5a145734e8d45e18a47b to your computer and use it in GitHub Desktop.
Apache-like rules for the PHP internal CLI server
<?php
// public/cliserver.php (router script)
if (php_sapi_name() !== 'cli-server') {
die('this is only for the php development server');
}
$path = $_SERVER['DOCUMENT_ROOT'].'/'.$_SERVER['SCRIPT_NAME'];
if (is_file($path)) {
return false;
}
function test($path) {
$file = $path . '/index.php';
if ($path == '/' || $path=='\\' || is_file($_SERVER['DOCUMENT_ROOT'] . $file)) {
$_SERVER['SCRIPT_NAME'] = $file;
require ltrim(ltrim($file, '\\'), '/');
return true;
}
$path = dirname($path);
return test($path);
}
test($_SERVER['SCRIPT_NAME']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment