2024-03-09 23:29:25 -05:00
|
|
|
<?php
|
|
|
|
class GoPage {
|
|
|
|
private $page;
|
|
|
|
private $socket;
|
|
|
|
private $template;
|
|
|
|
|
2024-03-10 18:47:52 -04:00
|
|
|
public function __construct($page, $socket = "/home/simponic/fruitvote/http.sock", $template = "../template.html") {
|
2024-03-09 23:29:25 -05:00
|
|
|
$this->page = $page;
|
|
|
|
$this->socket = $socket;
|
|
|
|
$this->template = $template;
|
|
|
|
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
|
|
if (file_exists($socket)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
usleep(100_000); // wait 100ms
|
|
|
|
}
|
|
|
|
}
|
2024-03-10 04:41:11 -04:00
|
|
|
|
2024-03-09 23:29:25 -05:00
|
|
|
public function go() {
|
|
|
|
$ch = curl_init();
|
|
|
|
$url = "http://localhost".$this->page;
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, $this->socket);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
2024-03-10 18:45:26 -04:00
|
|
|
// forward query params
|
|
|
|
$query = $_SERVER['QUERY_STRING'];
|
|
|
|
if ($query) {
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url."?".$query);
|
|
|
|
}
|
|
|
|
|
|
|
|
//forward post data
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-09 23:29:25 -05:00
|
|
|
$output = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
2024-03-10 18:45:26 -04:00
|
|
|
|
|
|
|
|
2024-03-09 23:29:25 -05:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$response = $this->go();
|
|
|
|
$template = file_get_contents($this->template);
|
|
|
|
return str_replace("{{content}}", $response, $template);
|
|
|
|
}
|
|
|
|
}
|