Configuring PHP to use Proxy Servers

If you have a script that needs to send traffic via a Proxy Server, one of the best options is to use PHP's cURL library.

Example Code: The code below is example code that was provided by one of our customers and may be similar to code you would use to configure your own PHP script. We have no way of authenticating this code or knowing whether or not it will work with your particular version of PHP. 

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $sURL); // Target URL
  curl_setopt($ch, CURLOPT_PROXY, $sProxyUrl); // Proxy IP:Port
  curl_setopt($ch, CURLOPT_PROXYUSERPWD, "proxy_user:pass"); // Proxy Username/Password
  curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 600);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0'); // some browser user agent string
  curl_setopt($ch, CURLOPT_REFERER, $sURL);
  $aHeaders = array( 'Expect:', 
  'Accept-Language: en-us; q=0.5,en; q=0.3', 
  'Accept: text/html,application/xhtml+xml,application/xml; q=0.9,*/*; q=0.8');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeaders);
  $result = utf8_decode(curl_exec($ch));


While we cannot cover every possible way that you can use our proxy servers in this short article, here are also a few useful How-To sites that can point you in the right direction:




Parameters: With cURL, note that you can specify a parameter to pass in a username and password as well as the IP Address and Port Number. Depending on how the authentication method on your account is set up, you may need to pass one or more of these parameters to the proxy servers when you connect.


Timeouts: Due to the nature of the Internet, there sometimes may be a delay in returning data to your script. Your script must be able to anticipate delays and handle them appropriately. In addition to handling delays yourself, if you are connecting with cURL, it has it's own timeout settings as well. If you need to increase your timeout allowed for your script, you may find it useful to increase the cURL timeout setting.


Human Emulation: It is necessary that some form of 'Human Emulation' be coded in to your script. Human Emulation is designed to make your script query websites as if a human was performing the queries themselves. Human Emulation delays are what will prevent your proxy servers from being blocked by websites and your script from returning errors. A good rule of thumb is to code in a random delay of 15 to 20 seconds between queries and increase it from there if necessary.


DISCLAIMER: This info is provided for informational purposes only. Trusted Proxies takes no responsibility for the technical accuracy of the above articles nor accepts any liability for the actions, outcomes, results or impacts on your scripts.


  • 24 Users Found This Useful
Was this answer helpful?

Related Articles

Configure Web CEO to Use Proxy Servers

When using Trusted Proxies proxy servers you will need to configure Web CEO to allow it to...

Configure Market Samurai to Use Proxy Servers

This solution has been tested for WebHarvy (v3.4.0.119) To add your Trusted Proxies proxy...

Configure Rank Tracker to Use Proxy Servers

Note: To learn how to use Rank Tracker with the Big-G Stealth Extractor click here.This solution...

Configure WebHarvy to Use Proxy Servers

This solution has been tested for WebHarvy (v3.4.0.119) To add your Trusted Proxies proxy...