email smartphone

Configure PHP Proxy Server

If you are running PHP applications on an IDNT Compute Cloud instance and want to access the internet, you must configure the IDNT Compute Cloud proxy server.

Stream Context for file_get_contents()

For file_get_contents(), you can use a stream context with proxy settings:

<?php
$context = stream_context_create([
    'http' => [
        'proxy' => 'tcp://proxy.idnt.net:3128',
        'request_fulluri' => true,
    ],
    'https' => [
        'proxy' => 'tcp://proxy.idnt.net:3128',
        'request_fulluri' => true,
    ]
]);

$content = file_get_contents('https://example.com', false, $context);

cURL Proxy Configuration

For cURL-based HTTP requests:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_PROXY, 'proxy.idnt.net:3128');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

Guzzle HTTP Client

If you are using Guzzle:

<?php
use GuzzleHttp\Client;

$client = new Client([
    'proxy' => 'http://proxy.idnt.net:3128'
]);

$response = $client->get('https://example.com');

Symfony HTTP Client

For Symfony HTTP Client:

<?php
use Symfony\Component\HttpClient\HttpClient;

$client = HttpClient::create([
    'proxy' => 'http://proxy.idnt.net:3128'
]);

$response = $client->request('GET', 'https://example.com');

Global Proxy Configuration with Environment Variables

You can also set environment variables that are automatically used by many PHP HTTP clients:

export http_proxy=http://proxy.idnt.net:3128
export https_proxy=http://proxy.idnt.net:3128
export HTTP_PROXY=http://proxy.idnt.net:3128
export HTTPS_PROXY=http://proxy.idnt.net:3128

Proxy Server Details

  • Proxy Server: proxy.idnt.net
  • Port: 3128
  • Protocol: HTTP
  • Authentication: Not required

Testing the Configuration

To test the proxy configuration, use:

<?php
$context = stream_context_create([
    'http' => [
        'proxy' => 'tcp://proxy.idnt.net:3128',
        'request_fulluri' => true,
    ]
]);

$content = file_get_contents('http://ifconfig.me', false, $context);
echo "Your IP: " . $content;

More Information

For more information about proxy configuration, see our related articles for Linux, WordPress, and NodeJS.