Create proxytest.php

This commit is contained in:
Namhyeon Go 2022-10-06 02:20:02 +09:00 committed by GitHub
parent 30164b9cb7
commit 5d03d52658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

36
proxytest.php Normal file
View File

@ -0,0 +1,36 @@
<?php
// HTTP proxy implementation with PHP socket
// Go Namhyeon <gnh1201@gmail.com>
// 2022-10-06
ini_set("default_socket_timeout", 1);
$data = json_decode(file_get_contents('php://input'), true);
$buffer_size = $data['chunksize'];
$port = intval($data['port']);
$hostname = $data['server'];
// TODO: HTTPS support
/*
if ($port == 443) {
$hostname = "ssl://" . $hostname;
}
*/
$fp = fsockopen($hostname, $port, $errno, $errstr, 1);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = base64_decode($data['data']);
fwrite($fp, $out);
$buf = null;
while (!feof($fp) && $buf !== false) {
$buf = fgets($fp, $buffer_size);
echo $buf;
}
fclose($fp);
}