php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29280 Add php.ini option to set default proxy for wrappers
Submitted: 2004-07-20 14:01 UTC Modified: 2010-12-20 14:03 UTC
Votes:32
Avg. Score:4.4 ± 0.8
Reproduced:27 of 27 (100.0%)
Same Version:13 (48.1%)
Same OS:12 (44.4%)
From: Progman2002 at gmx dot de Assigned: pollita
Status: Assigned Package: Streams related
PHP Version: * OS: *
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-07-20 14:01 UTC] Progman2002 at gmx dot de
Description:
------------
I'm behind a proxy so my local php version cannot access the internet directly. Every HTTP-Request must go throught the proxy. I have see that I can create my own http-wrapper with settings to use my proxy and use this metioned "context" as fourth parameter for the functions like fopen and file_get_contents. This works fine, but what about if I use third-party scripts, which just use file_get_contents($url) instead of file_get_contents($url, false, $context)? It is possible to change or modify the internal http-wrapper to use my proxy instead of creating a new http-wrapper with stream_*() so I can just use file_get_contents() and fopen() without the 'zcontext'-parameter?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-20 14:24 UTC] wez@php.net
I know what you mean (and we do have something planned), but can you please clarify which functions you are using to implement proxy support?
 [2004-07-20 14:52 UTC] Progman2002 at web dot de
sure:
---- PHP-Code:
<?php
    $opts = array('http' => array('request_fulluri' => true,
                                  'proxy' => 'tcp://192.168.0.1:8080'));

    $context = stream_context_create($opts);

    $url = "http://www.example.com/";

    $fp = fopen($url, 'r', false, $context);
    if (!$fp) {
        echo "nothing :(";
    } else {
        var_dump($fp);
        fclose($fp);
    }

    // and now without $context...

    $fp = fopen($url, 'r');
    if (!$fp) {
        echo "nothing :(";
    } else {
        var_dump($fp);
        fclose($fp);
    }
?>

The first call with $context works, the second doesnt:

---- Output:
resource(3) of type (stream) 
Warning: fopen(http://www.example.com/) [function.fopen]: failed to open stream: Connection timed out in /home/progman/public_html/test.php on line 19
nothing :(

---- Expected:
resource(3) of type (stream)
resource(4) of type (stream) // or an other resource-id
----
A php.ini-setting for proxys would be maybe better ;)
 [2004-07-22 14:47 UTC] wez@php.net
Current CVS now has stream_context_get_default() which returns the default context used by all newly created streams (unless explicitly overriden).

You can use this in your script (perhaps via auto_prepend) to set the proxy globally.

I know; an ini option for the proxy would be a good idea too, so let's ask Sara really nicely if she wouldn't mind adding that.
 [2004-07-22 16:47 UTC] progman2002 at gmx dot de
works fine.
---- PHPs snip ----
$opts = array('http' => array('request_fulluri' => true,
                              'proxy' => 'tcp://192.168.0.1:8080'));
stream_context_get_default($opts);
---- eos ----
works also as...
---- PHPs snip ----
$context = stream_context_get_default();
stream_context_set_option($context, 'http', 'proxy', 'tcp://192.168.0.1:8080');
stream_context_set_option($context, 'http', 'request_fulluri', true);
---- eos ----
... does

So, now I must wait until it is in the non-cvs package ;)
 [2004-07-24 06:17 UTC] pollita@php.net
Dunno why this was assigned to me when wez implemented it :)

Closing it up.  You can either grab the snapshot from snaps.php.net otherwise your wait will be until 5.1.0 is released.
 [2004-07-24 06:19 UTC] pollita@php.net
Ack! My bad... didn't see your note about making it an .ini option :)

 [2008-06-04 19:07 UTC] r13ckj at gmail dot com
I was just wondering whether this has been implemented?

My problem is outlined here: http://forums.devshed.com/php-development-5/default-proxy-settings-for-php4-5t-534829.html#post2054576

I've spent countless hours on this problem, so any help would be much appreciated.
 [2009-09-17 09:34 UTC] fuzzy76 at fuzzy76 dot net
Is that a yes or a no on the ini option? :) I need to use a proxy in my 
office, and this makes testing webapps really difficult.
 [2010-12-20 14:03 UTC] jani@php.net
-Summary: changing the default http-wrapper +Summary: Add php.ini option to set default proxy for wrappers -Package: Feature/Change Request +Package: Streams related -PHP Version: 5CVS +PHP Version: *
 [2011-04-05 11:29 UTC] play4fun_82 at yahoo dot com
Hi, i have the same problem. My solution was to pass through proxy server with cntml tunneling tool.
You configure cntml proxy to forward http request received on local host on a port to destination with proper authentication.

And in pear u just configure 
>pear config-set http_proxy 127.0.0.1:3128

3128 - is port configuret in cntlm(it can be any other free port).
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 14:01:50 2014 UTC