Skip to content

Commit

Permalink
Prevent PHP 8 from outputting fatal error when calling fsockopen() (#388
Browse files Browse the repository at this point in the history
)

* Prevent PHP 8 from outputting fatal error when calling fsockopen()

Since PHP 8, @ Error Suppression operator does not silent fatal errors anymore.
See https://php.watch/versions/8.0/fatal-error-suppression for more.

This change prevent PHP 8 from outputting
Warning Error: fsockopen(): Unable to connect to 127.0.0.1:9515 (Connection refused)

* Update src/ProcessManager/WebServerReadinessProbeTrait.php

Co-authored-by: Kévin Dunglas <[email protected]>
  • Loading branch information
jtraulle and dunglas authored Dec 25, 2020
1 parent 834b902 commit 0e722c1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ProcessManager/WebServerReadinessProbeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ trait WebServerReadinessProbeTrait
*/
private function checkPortAvailable(string $hostname, int $port, bool $throw = true): void
{
$resource = @fsockopen($hostname, $port);
$currentState = error_reporting();
error_reporting(0);
$resource = fsockopen($hostname, $port);
error_reporting($currentState);
if (\is_resource($resource)) {
fclose($resource);
if ($throw) {
Expand Down

0 comments on commit 0e722c1

Please sign in to comment.