php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23520 PEAR Remote calls do not use Proxy Setting
Submitted: 2003-05-06 20:52 UTC Modified: 2003-07-12 09:31 UTC
From: aashley at optimiser dot com Assigned: cox (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.2 OS: Gentoo Linux (2.4.20)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aashley at optimiser dot com
New email:
PHP Version: OS:

 

 [2003-05-06 20:52 UTC] aashley at optimiser dot com
I do all my development on an internal box who's only http access is through the network proxy. RPCs in the pear commandline program do not honour the http_proxy setting in pear and try to connect directly. This needless to say fails every time, as it is blocked by our firewall. Downloading of packages however does work and honours the proxy settings.

For Example:

This works:
dt-pc0144 root # pear install Pager
downloading Pager-1.0.7.tgz ...
...done: 4,591 bytes
install ok: Pager 1.0.7

This however doesnt:
dt-pc0144 root # pear list-all
PEAR_Remote::call: fsockopen(`pear.php.net', 80) failed


Below is my pear configuration and list of installed PEAR packages:
dt-pc0144 root # pear config-show
Configuration:
==============
+--------------------------------+-----------------+-------------------------------------+
| PEAR executables directory     | bin_dir         | /usr/bin
| PEAR documentation directory   | doc_dir         | /usr/share/pear/docs         |
| PHP extension directory        | ext_dir         | ./         |
| PEAR directory                 | php_dir         | /usr/share/pear
         |
| PEAR Installer cache directory | cache_dir       | /tmp/pear/cache
         |
| PEAR data directory            | data_dir        | /usr/share/pear/data
         |
| PHP CLI/CGI binary             | php_bin         | /usr/bin/php
         |
| PEAR test directory            | test_dir        | /usr/share/pear/tests
         |
| Cache TimeToLive               | cache_ttl       | 3600
         |
| Preferred Package State        | preferred_state | stable
         |
| Unix file mask                 | umask           | 22
         |
| Debug Log Level                | verbose         | 1
         |
| HTTP Proxy Server Address      | http_proxy      | http://proxy.perth.optimiser.com.au |
|                                |                 | :3128/
         |
| PEAR server                    | master_server   | pear.php.net
         |
| PEAR password (for             | password        | <not set>
         |
| maintainers)                   |                 |
         |
| Signature Handling Program     | sig_bin         | /usr/bin/gpg
         |
| Signature Key Directory        | sig_keydir      | /usr/etc/pearkeys
         |
| Signature Key Id               | sig_keyid       | <not set>
         |
| Package Signature Type         | sig_type        | gpg
         |
| PEAR username (for             | username        | <not set>
         |
| maintainers)                   |                 |
         |
+--------------------------------+-----------------+-------------------------------------+

Installed packages:
===================
+----------------------+----------+--------+
| Package              | Version  | State  |
| Archive_Tar          | 1.0      | stable |
| Console_Getopt       | 1.0      | stable |
| DB                   | 1.4b1    | beta   |
| HTML_QuickForm       | 3.0Beta1 | beta   |
| HTML_Table           | 1.4      | stable |
| HTTP                 | 1.2      | stable |
| Mail                 | 1.0.2    | stable |
| Mail_Mime            | 1.2.1    | stable |
| Net_SMTP             | 1.2.2    | stable |
| Net_Socket           | 1.0.1    | stable |
| PEAR                 | 1.0.1    | stable |
| PEAR_Info            | 1.0.3    | stable |
| Pager                | 1.0.7    | stable |
| PhpDocumentor        | 1.2.0rc1 | beta   |
| Spreadsheet_Excel_Wr | 0.3      | beta   |
| iter                 |          |        |
| XML_Parser           | 1.0.1    | stable |
| XML_RPC              | 1.0.4    | stable |
+----------------------+----------+--------+

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-07 01:41 UTC] arnaud@php.net
I've just checked with yesterday snapshot and it works well, proxy settings are honoured. Can you try latest cvs and give us feedback ?

<offtopic>
seeing your proxy address, would you happen to live in perth ?
</offtopic>
 [2003-05-07 03:00 UTC] aashley at optimiser dot com
Ive just installed PHP Version 4.3.2-RC3-dev (php4-STABLE-200305070530.tar.bz2 from snaps.php.net). It has upgraded the PEAR objects to 1.1.

I'm still getting the same failure.
dt-pc0144 root # pear list-all
PEAR_Remote::call: fsockopen(`pear.php.net', 80) failed

The pearcmd.php that is being executed has the following cvs version string:
// $Id: pearcmd.php,v 1.1.2.1 2003/04/11 23:48:39 ssb Exp $

<offtopic>
yup, perth, western australia, best city in the country :)
</offtopic>
 [2003-05-07 03:16 UTC] arnaud@php.net
Btw, could you do a 

pear config-set verbose 3
pear list-all

it should provide useful debugging info.
 [2003-05-07 03:50 UTC] aashley at optimiser dot com
hrmmm strange I set verbose to 3 but it hasnt made any change to the output, is the logging sent to a file?

dt-pc0144 root # pear config-set verbose 3
dt-pc0144 root # pear list-all
PEAR_Remote::call: fsockopen(`pear.php.net', 80) failed
 [2003-05-10 15:59 UTC] nicos@php.net
I can't reproduce it too.
Can you try to use fsockopen() with something else please to see if you have any problem with it?
 [2003-05-11 20:48 UTC] aashley at optimiser dot com
hrmmm no way to attach files to this thing, oh well be warned this is a long post.

I knocked up the following script to test 4 cases of accessing servers using fsockopen from my development server.
1. Access the server script running on
2. Access a site which the firewall will allow direct access to (another development box)
3. Access an external site that the firewall with disallow direct access to (www.php.net)
4. Access the same external site this time through the proxy server.

Script 
===================================================
<?php
                                                                                
echo "Connecting to local machine...\n";
$fp = fsockopen ("dt-pc0144.perth.optimiser.com.au", 80, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  fputs ($fp, "GET /test.html HTTP/1.0\r\nHost: dt-pc0144.perth.optimiser.com.au\r\n\r\n");
  while (!feof($fp)) {
    echo fgets ($fp,128);
  }
  fclose ($fp);
}
                                                                                
echo "\n=======================\n"
  ."\n"
  ."Connecting to box which firewall allows direct connect...\n";
$fp = fsockopen ("tuna.optimiser.com", 80, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  fputs ($fp, "GET /test.html HTTP/1.0\r\nHost: tuna.optimiser.com\r\n\r\n");
  while (!feof($fp)) {
    echo fgets ($fp,128);
  }
  fclose ($fp);
}
                                                                                
echo "\n=======================\n"
  ."\n"
  ."Connecting to box which firewall disallows direct connect...\n";
$fp = fsockopen ("www.php.net", 80, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  fputs ($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n\r\n");
  while (!feof($fp)) {
    echo fgets ($fp,128);
  }
  fclose ($fp);
}
                                                                                
echo "\n=======================\n"
  ."\n"
  ."Connecting to box which firewall disallows direct connect through proxy...\n";
$fp = fsockopen ("proxy.perth.optimiser.com.au", 3128, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  fputs ($fp, "GET http://www.php.net/ HTTP/1.0\r\nHost: proxy.perth.optimiser.com.au\r\n\r\n");
  while (!feof($fp)) {
    echo fgets ($fp,128);
  }
  fclose ($fp);
}
                                                                                
?>

===================================
End Script



Script Output
===================================
Connecting to local machine...
HTTP/1.1 200 OK^M
Date: Mon, 12 May 2003 01:41:31 GMT^M
Server: Apache/1.3.27 (Unix)  (Gentoo/Linux) PHP/4.3.2-RC3-dev mod_gzip/1.3.19.1a^M
Last-Modified: Mon, 12 May 2003 01:33:30 GMT^M
ETag: "340086-b-3ebef9ea"^M
Accept-Ranges: bytes^M
Content-Length: 11^M
Connection: close^M
Content-Type: text/html^M
^M
It Worked!
                                                                                
=======================
                                                                                
Connecting to box which firewall allows direct connect...
HTTP/1.1 200 OK^M
Date: Mon, 12 May 2003 01:41:31 GMT^M
Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.2 PHP/4.3.0 mod_perl/1.26^M
Last-Modified: Mon, 12 May 2003 01:35:08 GMT^M
ETag: "719d0-b-3ebefa4c"^M
Accept-Ranges: bytes^M
Content-Length: 11^M
Connection: close^M
Content-Type: text/html^M
^M
It Worked!
                                                                                
=======================
                                                                                
Connecting to box which firewall disallows direct connect...
                                                                                
Warning: fsockopen(): php_hostconnect: connect failed in /home/aashley/web/fopen.php on line 32
                                                                                
Warning: fsockopen(): unable to connect to www.php.net:80 in /home/aashley/web/fopen.php on line 32
Connection timed out (110)<br>
                                                                                
=======================
                                                                                
Connecting to box which firewall disallows direct connect through proxy...
HTTP/1.0 200 OK^M
Date: Mon, 12 May 2003 01:30:47 GMT^M
Content-Type: text/html;charset=ISO-8859-1^M
Server: Apache/1.3.26 (Unix) PHP/4.3.2-RC3-dev^M
X-Powered-By: PHP/4.3.2-RC3-dev^M
Last-Modified: Mon, 12 May 2003 01:08:10 GMT^M
Content-Language: en^M
X-Cache: HIT from rs1.php.net^M
Via: 1.0 netcache (NetCache NetApp/5.3.1R2D4)^M
X-Cache: HIT from proxy.perth.optimiser.com.au^M
Proxy-Connection: close^M
^M
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <title>PHP: Hypertext Preprocessor</title>

<snip a whole lot of website>

</body>
</html>
<!-- 0.021165013313293 -->


=====================
End Output
 [2003-05-26 08:51 UTC] arnaud@php.net
Is it still buggy ?
 [2003-05-26 22:13 UTC] aashley at optimiser dot com
ive just upgraded php on my system to the php4-STABLE-200305270130 snapshot. still experiencing the problem. downloads use the proxy but all the rpc calls timeout with:

dt-pc0144 php4-STABLE-200305270130 # pear list-all PEAR_Remote::call: fsockopen(`pear.php.net', 80) failed
 [2003-06-23 04:35 UTC] mj@php.net
Just to be sure that you are using the right PEAR binary: Can you please run "pear -V" and tell us the output?
 [2003-06-23 20:10 UTC] aashley at optimiser dot com
dt-pc0144 root # pear -V
PEAR Version: 1.1
PHP Version: 4.3.2
Zend Engine Version: 1.3.0
 [2003-06-24 01:21 UTC] mj@php.net
Can you please try to upgrade to 1.2RC1? ("pear upgrade PEAR")
 [2003-06-24 01:41 UTC] aashley at optimiser dot com
have upgraded the PEAR package as instructed, no RC1 available that way 1.2beta2 was installed

root@dt-pc0144 root # pear upgrade PEAR
downloading PEAR-1.2b2.tgz ...
...done: 82,854 bytes
upgrade ok: PEAR 1.2b2
root@dt-pc0144 root # pear -V
PEAR Version: 1.2b2
PHP Version: 4.3.2
Zend Engine Version: 1.3.0
root@dt-pc0144 root # pear list-all
PEAR_Remote::call: fsockopen(`pear.php.net', 80) failed
 [2003-07-03 01:15 UTC] aashley at optimiser dot com
To try to rule out if its my install or not, I've built up a new server with RedHat 9, its stock install of PHP, the PEAR command experiences the same problems.

Ive built and installed from source (after removing the RH PHP RPMS) PHP-4.3.2 and still experience the same problems, RPC calls do not make use of the proxy settings
 [2003-07-11 01:27 UTC] arnaud@php.net
Could you dive into the pear code and try to find the problem ? i mean add echo statements when it is about to make the connection and stuff.

I have a proxy with authorization at work and things work fine.
 [2003-07-11 01:33 UTC] aashley at optimiser dot com
yeah I'll have a go at it prob monday morning, its almost knock off time on friday here at the moment :)
 [2003-07-11 01:52 UTC] aashley at optimiser dot com
okay i found where the problem in the code is. In PEAR_Remote when doing an XMLRPC call if the xmlrpc extension is available then it is used directly without using the XML_RPC object.

the problem is in that PEAR_Remote::call_epi() does not make use of the proxy settings at all, while PEAR_Remote::call() if making use of the XML_RPC object does.
 [2003-07-11 02:12 UTC] arnaud@php.net
can you have a look at it tomas ?
 [2003-07-11 02:13 UTC] aashley at optimiser dot com
hrmm i really should learn when to call it quits and go home.

anyway I have made a patch for PEAR/Remote.php based on the code in XML/RPC.php to fix this problem, where/how should I go about submitting it?
 [2003-07-11 02:16 UTC] arnaud@php.net
Post the diff here
 [2003-07-11 02:20 UTC] aashley at optimiser dot com
--- Remote.orig.php     2003-07-11 15:01:28.000000000 +0800
+++ Remote.php  2003-07-11 15:13:07.000000000 +0800
@@ -204,8 +204,21 @@
             return $this->raiseError("PEAR_Remote::call: no master_server configured");
         }
         $server_port = 80;
-        $fp = @fsockopen($server_host, $server_port);
-        if (!$fp) {
+        $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
+        if ($proxy = parse_url($this->config->get('http_proxy'))) {
+            $proxy_host = @$proxy['host'];
+            $proxy_port = @$proxy['port'];
+            $proxy_user = @$proxy['user'];
+            $proxy_pass = @$proxy['pass'];
+        }
+        if ($proxy > '') {
+            $fp = @fsockopen($proxy_host, $proxy_port);
+        } else {
+            $fp = @fsockopen($server_host, $server_port);
+        }
+        if (!$fp && $proxy_host > '') {
+            return $this->raiseError("PEAR_Remote::call: fsockopen(`$proxy_host', $proxy_port) failed");
+        } elseif (!$fp) {
             return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host', $server_port) failed");
         }
         $len = strlen($request);
@@ -225,14 +238,29 @@
             $maxAge = '';
         };
          
+        if ($proxy_host > '' && $proxy_user > '') {
+            $req_headers .= 'Proxy-Authorization: Basic '
+                .base64_encode($proxy_user.':'.$proxy_pass)
+                ."\r\n";
+        }
+
         if ($this->config->get('verbose') > 3) {
             print "XMLRPC REQUEST HEADERS:\n";
             var_dump($req_headers);
             print "XMLRPC REQUEST BODY:\n";
             var_dump($request);
         }
+
+        if ($proxy_host > '') {
+            $post_string = "POST http://".$server_host;
+            if ($proxy_port > '') {
+                $post_string .= ':'.$server_port;
+            }
+        } else {
+            $post_string = "POST ";
+        }
          
-        fwrite($fp, ("POST /xmlrpc.php$maxAge HTTP/1.0\r\n$req_headers\r\n$request"));
+        fwrite($fp, ($post_string."/xmlrpc.php$maxAge HTTP/1.0\r\n$req_headers\r\n$request"));
         $response = '';
         $line1 = fgets($fp, 2048);
         if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {
 [2003-07-11 02:22 UTC] aashley at optimiser dot com
hasnt been tested with authenticating proxies, but does work with non-authenticating squid we have running here.
 [2003-07-11 03:47 UTC] cox@php.net
Hi,

Please send the diff -u against the lastest CVS file (in the repository php-src/pear/PEAR/Remote.php) to me cox@idecnet.com, the patch posted here doesn't apply cleanly.

Thanks,

Tomas V.V.Cox
 [2003-07-12 09:31 UTC] cox@php.net
I've commited your patch, will be included in the next PEAR package release.

Thanks!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 19:03:37 2021 UTC