Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 committed Mar 1, 2024
1 parent cad0540 commit 6173638
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/libraries/Console/Commands/Server/Serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,26 @@ public function run(array $params)
/**
* Find an available port
*/
protected function findAvailablePort(string $host, int $port): ?int
protected function findAvailablePort(string $host, int $startPort): ?int
{
$maxTries = $this->maxTries;
$waitTime = $this->waitTimeInSeconds; // Tiempo de espera entre intentos en segundos

for ($i = 0; $i < $maxTries; $i++) {
$maxTries = $this->maxTries;
for ($port = $startPort; $port < $startPort + $maxTries; $port++) {
if ($this->checkPort($host, $port)) {
return $port;
}

sleep($waitTime); // Espera antes de intentar nuevamente
}

return null;
}

/**
* Check if a port is available
*/

protected function checkPort(string $host, int $port): bool
{
$socket = @fsockopen($host, $port);
if ($socket !== false) {
fclose($socket);
return false;
}
return true;
$url = "http://$host:$port";
$headers = @get_headers($url);

return !empty($headers);
}


/**
* Shutdown the server
Expand Down

0 comments on commit 6173638

Please sign in to comment.