Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 809eec9

Browse files
committed
Fixed bugs
1 parent 9f4f316 commit 809eec9

File tree

3 files changed

+11
-46
lines changed

3 files changed

+11
-46
lines changed

hyper-run

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ if (is_file(__DIR__ . '/autoload.php')) {
2626
require __DIR__ . '/autoload.php';
2727
} elseif (is_file(__DIR__ . '/../../autoload.php')) {
2828
require __DIR__ . '/../../autoload.php';
29+
} elseif (is_file(__DIR__ . '/vendor/autoload.php')) {
30+
require __DIR__ . '/vendor/autoload.php';
2931
} else {
3032
fwrite(STDERR,
3133
"You need to set up the project dependencies using the following commands:\n" .

src/BuiltinServerProcess.php

+9-25
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,21 @@ public function __construct($directory = '.')
2222
$cmd = "lsof -i4TCP:$port | perl -ane '{if(\$F[8]=~/^[^:]+:(\d+)/){print \$1}}'";
2323
$outputs = $this->execCommand($cmd);
2424
} while (!empty($outputs));
25-
$pid = $this->fork($port);
26-
if (!empty($pid)) {
27-
$this->pid = $pid;
28-
$this->port = $port;
29-
usleep(50000);
30-
return;
25+
$escdir = escapeshellarg($directory);
26+
$pid = (int)current($this->execCommand("cd $escdir; php -S localhost:$port 1>&2 & printf \$!"));
27+
if ($pid === 0) {
28+
throw new \UnexpectedValueException;
3129
}
3230
$this->info("Listening on localhost:$port");
33-
$escdir = escapeshellarg($directory);
34-
$this->execCommand("cd $escdir; php -S localhost:$port >/dev/null 2>&1", false);
35-
exit;
31+
$this->pid = $pid;
32+
$this->port = $port;
33+
usleep(50000);
3634
}
3735

3836
public function __destruct()
3937
{
40-
if (empty($this->port)) {
41-
return;
42-
}
43-
$search = "php -S localhost:$this->port";
44-
$outputs = $this->execCommand("ps | grep '$search'");
45-
foreach ($outputs as $item) {
46-
if (
47-
strpos($item, 'grep') === false &&
48-
strpos($item, 'sh') === false &&
49-
strpos($item, $search) !== false
50-
) {
51-
$pid = (int)$item;
52-
$this->execCommand("kill $pid 2>/dev/null");
53-
$this->info("Killed localhost:$this->port");
54-
return;
55-
}
38+
if ($this->pid !== 0) {
39+
posix_kill($this->pid, SIGKILL);
5640
}
5741
}
5842

src/ProxyProcess.php

-21
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@ public function listen()
4949
}
5050
}
5151

52-
public function __destruct()
53-
{
54-
if (empty($this->port)) {
55-
return;
56-
}
57-
$search = "php -S localhost:$this->port";
58-
$outputs = $this->execCommand("ps | grep '$search'");
59-
foreach ($outputs as $item) {
60-
if (
61-
strpos($item, 'grep') === false &&
62-
strpos($item, 'sh') === false &&
63-
strpos($item, $search) !== false
64-
) {
65-
$pid = (int)$item;
66-
$this->execCommand("kill $pid 2>/dev/null");
67-
$this->info("Killed localhost:$this->port");
68-
return;
69-
}
70-
}
71-
}
72-
7352
private function getSocketServer($use_ssl)
7453
{
7554
$context = stream_context_create(

0 commit comments

Comments
 (0)