|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 |
+----------------------+----------+--------+
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 22 09:00:01 2025 UTC |
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 OutputCan you please try to upgrade to 1.2RC1? ("pear upgrade PEAR")--- 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)) {