- Create index.php
- Start php built-in server on local by command:
php -S localhost:8000
- Publish local server to serveo:
ssh -o ServerAliveInterval=60 -R 80:localhost:8000 serveo.net
Last active
August 1, 2019 08:03
-
-
Save dzungtran/880e416db393042536d1951a028ab00a to your computer and use it in GitHub Desktop.
Create request logging server on local
This file contains hidden or 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
<?php | |
class DumpHTTPRequestToFile { | |
public function execute($targetFile) { | |
$data = sprintf( | |
"%s %s %s\nHTTP headers:\n", | |
$_SERVER['REQUEST_METHOD'], | |
$_SERVER['REQUEST_URI'], | |
$_SERVER['SERVER_PROTOCOL'] | |
); | |
foreach ($this->getHeaderList() as $name => $value) { | |
$data .= $name . ': ' . $value . "\n"; | |
} | |
$data .= "\nRequest body:\n"; | |
if (isset($_SERVER["CONTENT_TYPE"]) && $_SERVER["CONTENT_TYPE"] == "multipart/form-data") { | |
$data .= print_r($_POST, true); | |
} else { | |
$data .= file_get_contents('php://input'); | |
} | |
file_put_contents( | |
$targetFile, | |
"=============== Request time: " . date(DATE_RFC2822) . " ==================\n\n". $data . "\n\n", FILE_APPEND | |
); | |
echo("OK"); | |
} | |
private function getHeaderList() { | |
$headerList = []; | |
foreach ($_SERVER as $name => $value) { | |
if (preg_match('/^HTTP_/',$name)) { | |
// convert HTTP_HEADER_NAME to Header-Name | |
$name = strtr(substr($name,5),'_',' '); | |
$name = ucwords(strtolower($name)); | |
$name = strtr($name,' ','-'); | |
// add to list | |
$headerList[$name] = $value; | |
} | |
} | |
return $headerList; | |
} | |
} | |
(new DumpHTTPRequestToFile)->execute('./files/' . date('Ymd') . '.txt'); |
This file contains hidden or 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
cd ~/your_folder & php -S localhost:6969 &> /dev/null & | |
ssh -o ServerAliveInterval=60 -R your_sub_domain:80:localhost:6969 serveo.net |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment