-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleNoAsync.php
53 lines (41 loc) · 1006 Bytes
/
ExampleNoAsync.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?hh // strict
// Example name: noasync
class ExampleNoAsync implements ExampleInterface
{
public function __construct() {}
public function run(): void
{
$first = $this->firstFunc();
$second = $this->secondFunc();
$finalResult = $first + $second;
echo "Final result is $finalResult\n";
}
private function firstFunc(): int
{
return $this->computeResult(__FUNCTION__, 7, 3);
}
private function secondFunc(): int
{
return $this->computeResult(__FUNCTION__, 5, 2);
}
private function computeResult(
string $funcName,
int $sleepTime,
int $finalResult
): int
{
echo "$funcName invoked and sleeping for $sleepTime seconds\n";
$url = sprintf(
'http://127.0.0.1:8080/server.php?sleep=%d&return=%d',
$sleepTime,
$finalResult
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$result = intval($result);
echo "$funcName is returning $result\n";
return $result;
}
}