Skip to content

Commit

Permalink
Slight optimization for isConnected when not using a unix based socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadSikorra committed Jan 22, 2023
1 parent 96a20d3 commit 6d4adb2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/FreeDSx/Socket/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,17 @@ public function block(bool $block)
*/
public function isConnected() : bool
{
if ($this->socket === null) {
return false;
}

// Slight optimization. The feof() method should be more accurate and unix socket should be less likely.
// In PHP 8.2 feof is not accurate for checking a UNIX socket.
if ($this->options['transport'] !== 'unix') {
return !@\feof($this->socket);
}

// The is_resource() function will also check if a resource is connected or not.
// Previously this used feof(), which was no reliable on PHP 8.2 with certain transports.
return \is_resource($this->socket);
}

Expand Down

0 comments on commit 6d4adb2

Please sign in to comment.