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: 2021-07-27 12:19 UTC
Votes:64
Avg. Score:4.3 ± 0.9
Reproduced:47 of 53 (88.7%)
Same Version:26 (55.3%)
Same OS:24 (51.1%)
From: Progman2002 at gmx dot de Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [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

Pull Requests

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).
 [2017-10-24 06:23 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: pollita +Assigned To:
 [2019-04-23 07:49 UTC] m dot weinstein at swp dot de
It's 2019. Anything new on this issue?
 [2019-08-01 18:10 UTC] sid dot asad dot siddiqui at gmail dot com
Having PHP respect the HTTP_PROXY environment variable would be great. Most programs do it. It was a surprise to see that PHP does not support it. It is even bigger surprise to see that there no way to set proxy globally. The only possible solution requires making modifications in the source, which is so much undesirable.
 [2021-07-27 12:19 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-07-27 12:19 UTC] cmb@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.

That.  Anything else (INI directive, environment variable, etc.)
needs someone to pursue the RFC process[1].

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC