Eve
Eve

Reputation: 41

Using HTTP proxy in PHP

May you give me an example for using an HTTP proxy in PHP?

Upvotes: 4

Views: 6370

Answers (1)

thomasrutter
thomasrutter

Reputation: 117401

If you want to use PHP to make an HTTP request via a proxy, you can use the proxy context option.

Example:

$opts = array('http' =>
    array(
        'proxy'  => 'tcp://proxy.example.com:5100',
    )
);

$context  = stream_context_create($opts);
$result = file_get_contents('http://example.com/somefile.html', false, $context);

Upvotes: 4

Related Questions