     [Answers](https://scrapfly.io/blog)   /  [http](https://scrapfly.io/blog/tag/http)   /  [How to use proxies with PHP Guzzle?](https://scrapfly.io/blog/answers/how-to-use-proxies-php-guzzle)   # How to use proxies with PHP Guzzle?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) May 16, 2023 1 min read [\#http](https://scrapfly.io/blog/tag/http) [\#php](https://scrapfly.io/blog/tag/php) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle "Share on LinkedIn")    

 

 

PHP's [Guzzle](https://docs.guzzlephp.org/en/stable/) is a popular HTTP client used when web scraping with PHP and proxies are an integral part of web scraping so here's a quick introduction on how to use proxies with Guzzle:

php```php
<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

// Proxy pattern is:
// scheme://username:password@IP:PORT
// For example:
// no auth HTTP proxy:
$my_proxy = "http://160.11.12.13:1020";
// proxy with authentication
$my_proxy = "http://my_username:my_password@160.11.12.13:1020";
// Note: that username and password should be url encoded if they contain URL sensitive characters like "@":
$my_proxy = 'http://'.urlencode('foo@bar.com').':'.urlencode('password@123').'@160.11.12.13:1020';

$client = new Client([
    // Base URI is used with relative requests
    'base_uri' => 'https://httpbin.dev',
    // You can set any number of default request options.
    'timeout'  => 2.0,
    'proxy' => [
        'http'  => $my_proxy,      // This proxy will be applied to all 'http' URLs
        'https' => $my_proxy,      // This proxy will be applied to all 'https' URLs
        'https://httpbin.dev' => $my_proxy,  // This proxy will be applied only to 'https://httpbin.dev'
    ]
]);

$response = $client->request('GET', '/ip');
$body = $response->getBody();
print($body);
```



Guzzle does not support SOCKS proxies and the only available options are php's curl library or [buzz](https://github.com/kriswallsmith/Buzz).

Note that Guzzle proxy can also be set through the standard `*_PROXY` environment variables:

shell```shell
$ export HTTP_PROXY="http://160.11.12.13:1020"
$ export HTTPS_PROXY="http://160.11.12.13:1020"
$ export ALL_PROXY="socks://160.11.12.13:1020"
```



When web scraping, it's best to rotate proxies for each request. For that see our article: [How to Rotate Proxies in Web Scraping](https://scrapfly.io/blog/posts/how-to-rotate-proxies-in-web-scraping)



 

    



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-use-proxies-php-guzzle) 



 ## Related Articles

 [  

 http data-parsing 

### Web Scraping With PHP 101

Introduction to web scraping with PHP. How to handle http connections, parse html files for data, best practices, tips a...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-php-101) [  

 curl 

### How to Use cURL GET Requests

Here's everything you need to know about cURL GET requests and some common pitfalls you should avoid.

 

 ](https://scrapfly.io/blog/posts/how-to-use-curl-get-requests) [  

 http tools 

### How to Use cURL For Web Scraping

In this article, we'll go over a step-by-step guide on sending and configuring HTTP requests with cURL. We'll also explo...

 

 ](https://scrapfly.io/blog/posts/how-to-use-curl-for-web-scraping) 

  ## Related Questions

- [ Q How to use proxies with Python httpx? ](https://scrapfly.io/blog/answers/how-to-use-proxies-python-httpx)
- [ Q How to find HTML elements by text value with BeautifulSoup ](https://scrapfly.io/blog/answers/how-to-find-html-elements-by-text-with-beautifulsoup)
- [ Q How to use proxies with NodeJS axios? ](https://scrapfly.io/blog/answers/how-to-use-proxies-nodejs-axios)
- [ Q How to use cURL in Python? ](https://scrapfly.io/blog/answers/how-to-use-curl-in-python)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)