blob: 864c1f7648c2298df1d257ebaaf981ee90802946 (
plain)
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
31
32
33
34
35
36
37
38
39
|
<?php
class GoPage {
private $page;
private $socket;
private $template;
public function __construct($page, $socket = "/home/simponic/fruitvote/http.sock", $template = "../template.html") {
$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
}
}
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);
}
}
|