Re: Can php be configured to browse through a proxy?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your answer, it's a pitty that a proxy cannot be specified via
php.ini, but anyway.
I must say that the information is distributed on many parts of the
documentation:
.- http://www.php.net/manual/en/context.http.php (for the parameters
supported by the http/https context)
You get there following this path:
function.stream-context-set-default.php -> Supported Protocols and Wrappers
-> wrappers.http.php -> context.http.php

It's a bit too much, to try to ammend that, I've added a note in
the function.stream-context-set-default.php page that should clarify the
setup of proxy with default context.
I'd be glad if someone had a look on that and revised the code.

The code is this:
<?php
//Code snippet taken from
//
http://stackoverflow.com/questions/1336262/file-get-contents-behind-a-proxy

php $auth = base64_encode('LOGIN:PASSWORD');

$aContext = array(
    'http' => array(
        'proxy' => 'tcp://192.168.0.2:3128',
        'request_fulluri' => true,
        'header' => "Proxy-Authorization: Basic $auth",
    ),
);
stream_context_set_default($aContext);

$sFile = file_get_contents("http://www.google.com";, False);

echo $sFile;
?>


2012/2/14 Matijn Woudt <tijnema@xxxxxxxxx>

> On Tue, Feb 14, 2012 at 5:41 PM, Joan <aseques@xxxxxxxxx> wrote:
> > There is some information about configuring php to use a proxy when
> > connecting to external urls.
> >
> > According to some sources the proper setup option is by using
> > the stream-context-set-default function (
> > http://www.php.net/manual/en/function.stream-context-set-default.php)
> > Still I have not been able to find any reference about if it can be set
> on
> > php.ini (so all the instances of php use it)
> >
> > Also there is this bug that has been assigned since 2010 and still have
> not
> > changed (29280)
> > https://bugs.php.net/bug.php?id=29280
> >
> > Any information about this will be well received.
> >
> > Thanks,
> >
> > Joan
>
> Hi,
>
> AFAIK there's no such setting in php.ini. If you want to have it set
> allways, you could use the php.ini setting auto_prepend_file to run a
> simple php script (containing stream_context_set_default) before each
> php file is parsed.
>
> - Matijn
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux