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 #3372

net_socket needs to support stream transport specification to work w/ php 5

Details

Submitted2005-02-03 16:52 UTC
Fromliamr at umich dot edu
Assignedchagenbu
StatusClosed
PackageNet_Socket
PHP Version5.0.3
OSlinux 2.4.28
Roadmaps(Not assigned)

Comments

[2005-02-03 16:52 UTC] liamr at umich dot edu

Description:
------------
fsockopen in php5 seems to be pickier about requiring the stream transport specification ( 'tcp://', 'unix://', etc ) when opening sockets.

PHP 4 would allow you to do...

$fp = fsockopen( '/tmp/example.sock, 0, $errno,
$errstr, 30 );

PHP 5 requires

$fp = fsockopen( 'unix:///tmp/example.sock, 0,
$errno, $errstr, 30 );

As Net_Socket::connect uses fsockopen and pfsockopen, it should be able to handle the transport specification, and currently doesn't.

Reproduce code:
---------------
$socket = &new Net_Socket();
$socket->connect( 'unix:///tmp/example.sock', 0, true, 30);

Expected result:
----------------
A unix socket should get opened

Actual result:
--------------
If your /etc/resolv.conf contains..

search example.com

Net_Socket tries to open a tcp socket to a host named

unix:///tmp/example.sock.example.com

6294 socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 4
6294 connect(4, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("www.xxx.yyy.zzz")}, 28) = 0
6294 send(4, "\254\320\1\0\0\1\0\0\0\0\0\0\21unix:///tmp/example.sock\5example\3com\0\0\
1\0\1", 45, 0) = 45
6294 gettimeofday({1107447499, 264462}, NULL) = 0
6294 poll([{fd=4, events=POLLIN, revents=POLLIN}], 1, 5000) = 1
6294 ioctl(4, FIONREAD, [100]) = 0
6294 recvfrom(4, "\254\320\205\203\0\1\0\0\0\1\0\0\21unix:///tmp/example.sock\5example\3
com\0\0\1\0\1\300\36\0\6\0\1\0\0p\200\0+\3dns\3itd\300\36\nhostmaster\300\36\v\3
63k\20\0\0p\200\0\0008@\0$\352\0\0\0p\200", 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("www.xxx.yyy.zzz")}, [16]) = 100
6294 close(4) = 0

[2005-02-03 17:20 UTC] liamr at umich dot edu

This patch seems to work...

diff -U 2 /tmp/Socket.php Socket.php
--- /tmp/Socket.php 2005-02-03 12:08:34.000000000 -0500
+++ Socket.php 2005-02-03 12:10:12.000000000 -0500
@@ -102,5 +102,5 @@
if (!$addr) {
return $this->raiseError('$addr cannot be empty');
- } elseif (strspn($addr, '.0123456789') == strlen($addr) || substr($addr, 0, 1) == '/') {
+ } elseif (strspn($addr, '.0123456789') == strlen($addr) || substr($addr, 0, 1) == '/' || strstr($addr, '://')) {
$this->addr = $addr;
} else {