-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.php
More file actions
30 lines (24 loc) · 1.22 KB
/
server.php
File metadata and controls
30 lines (24 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$publicPath = getcwd();
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? ''
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists($publicPath.$uri)) {
return false;
}
// Handle logging with error suppression to prevent broken pipe errors
$formattedDateTime = date('D M j H:i:s Y');
$requestMethod = $_SERVER['REQUEST_METHOD'];
$remoteAddress = $_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT'];
// Use error suppression and check if stdout is available before writing
// This prevents broken pipe errors during testing and when connections are closed
if (defined('STDOUT') && is_resource(STDOUT)) {
@file_put_contents('php://stdout', "[$formattedDateTime] $remoteAddress [$requestMethod] URI: $uri\n");
} elseif (php_sapi_name() === 'cli-server') {
// For PHP built-in server, try to write to stdout stream directly with error suppression
@file_put_contents('php://stdout', "[$formattedDateTime] $remoteAddress [$requestMethod] URI: $uri\n");
}
require_once $publicPath.'/index.php';