tilde.club/html/public/fruitvote/GoPage.php
Lizzy Hunt 1115512817
All checks were successful
continuous-integration/drone/push Build is passing
remove bad database flag, bad curl options, and add sigint listener
2024-03-10 01:25:22 -07:00

49 lines
1.4 KiB
PHP

<?php
class GoPage {
private $page;
private $socket;
private $template;
public function __construct($page, $socket = "/home/simponic/fruitvote/http.sock", $start_cmd="/home/simponic/fruitvote/start.sh", $template = "../template.html") {
$this->page = $page;
$this->socket = $socket;
$this->template = $template;
// test if socket exists
if (!file_exists($socket)) {
// start the server
exec($start_cmd);
}
for ($i = 0; $i < 10; $i++) {
if (file_exists($socket)) {
break;
}
usleep(100_000); // wait 100ms
}
if (!file_exists($socket)) {
throw new Exception("Could not start server");
}
}
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);
$output = curl_exec($ch);
curl_close($ch);
// todo: get headers / cookies, forward back response
return $output;
}
public function render() {
$response = $this->go();
$template = file_get_contents($this->template);
return str_replace("{{content}}", $response, $template);
}
}