Skip to content

Commit

Permalink
fix: prevent warning of fsockopen
Browse files Browse the repository at this point in the history
Fixed:

Unable to connect to 127.0.0.1:8888 (Connection refused)

Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Jan 29, 2025
1 parent 5926524 commit d57d2fc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/Handler/CertificateEngine/CfsslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,13 @@ private function wakeUp(): void {
private function portOpen(): bool {
$host = parse_url($this->getCfsslUri(), PHP_URL_HOST);
$port = parse_url($this->getCfsslUri(), PHP_URL_PORT);
try {
$socket = fsockopen($host, $port, $errno, $errstr, 0.1);
} catch (\Throwable $th) {
}
if (isset($socket) && is_resource($socket)) {
fclose($socket);
return true;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$socket) {
return false;
}
return false;
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 0, 'usec' => 100000]); // 100ms
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => 0, 'usec' => 100000]);
return @socket_connect($socket, $host, $port);
}

private function getServerPid(): int {
Expand Down

0 comments on commit d57d2fc

Please sign in to comment.