PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_Socket » Bug #3331

PHP warning instead of PEAR_Error if (p)fsockopen() fails

Details

Submitted2005-01-30 19:35 UTC
Frommfonda at dotgeek dot org
StatusBogus
PackageNet_Socket
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-01-30 19:35 UTC] mfonda at dotgeek dot org

Description:
------------
In the connect() method of Net_Socket, it is supposed to raise a
PEAR_Error if (p)fsockopen() fails, but there is no error
suppressing on (p)fsockopen(), so if it fails, there is a PHP error
instead.

Reproduce code:
---------------
require_once 'Net/Socket.php';
$sock =& new Net_Socket();
if (PEAR::isError($sock->connect('www.nonexistanthost.fake', 21))) {
echo 'this is how it should work';
}

Expected result:
----------------
this is how it should work

Actual result:
--------------
PHP Warning: fsockopen(): php_network_getaddresses:
getaddrinfo failed: Name or service not known
in /usr/share/pear/Net/Socket.php on line 108

Warning: fsockopen(): php_network_getaddresses: getaddrinfo
failed: Name or service not known
in /usr/share/pear/Net/Socket.php on line 108
PHP Warning: fsockopen(): unable to connect to
www.nonexistanthost.fake:21 (Unknown error)
in /usr/share/pear/Net/Socket.php on line 108

Warning: fsockopen(): unable to connect to
www.nonexistanthost.fake:21 (Unknown error)
in /usr/share/pear/Net/Socket.php on line 108




It would be very easy to fix this bug. All you have to do is simple
add an '@' infront of (p)fsockopen() to suppress the error, and
then the PEAR_Error will be raised if it fails. The code to raise
the PEAR_Error is already in place, it will just never get executed
if there is infact an error because PHP will die.

To fix, just change lines 106 / 108 to:
106: $fp = @$openfunc($this->addr, $this->port, $errno, $errstr,
$this->timeout);

108: $fp = $openfunc($this->addr, $this->port, $errno, $errstr);

[2005-01-30 19:39 UTC] mfonda at dotgeek dot org

Excuse me, it is just a PHP warning, not a fatal error, but a
PEAR_Error is still the expected result, not a PHP warning

[2005-01-31 07:17 UTC] mfonda at dotgeek dot org

My apologies, you are right. I thought I had upgraded to the latest version but apparently I hadn't. Anyways, I thought I had said "irrelevant" for PHP version, but you're right, makes no sense to say for pacakage version.