I want to let the php file_get_content function connect to network via system-wide proxy. I tried to add the following lines in /etc/environment:
http_proxy=http://localhost:3128/
HTTP_PROXY=http://localhost:3128/
https_proxy=http://localhost:3128/
HTTPS_PROXY=http://localhost:3128/
But it does not work for file_get_content, although it works for wget. I also tried to add the following lines to /etc/profile:
PROXY_URL="http://localhost:3128/"
export http_proxy="$PROXY_URL"
export https_proxy="$PROXY_URL"
export ftp_proxy="$PROXY_URL"
# For curl
export HTTP_PROXY="$PROXY_URL"
export HTTPS_PROXY="$PROXY_URL"
export FTP_PROXY="$PROXY_URL"
Again, it does not work. I created the following test.php:
<?php
$aContext = array(
'http' => array(
'proxy' => 'tcp://localhost:3128',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents("https://www.google.com", False, $cxContext);
echo $sFile;
This script does work. But since I cannot modify all the source code that contains file_get_contents, I need a system-wide proxy. How can I do it?