{"id":20709930,"url":"https://github.com/oxylabs/guzzle-proxy","last_synced_at":"2026-06-01T00:32:16.210Z","repository":{"id":178549626,"uuid":"619543009","full_name":"oxylabs/guzzle-proxy","owner":"oxylabs","description":"How to Set Up Proxies in Guzzle: PHP Tutorial","archived":false,"fork":false,"pushed_at":"2025-02-11T13:00:02.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T14:22:07.209Z","etag":null,"topics":["guzzle","guzzle-php-library","guzzle-proxy","php","php-framework","php-library","php-tutorial","proxy-list","proxy-list-github","proxy-rotator","proxy-site","rotating-proxy","socks5-proxy-list","socks5-server"],"latest_commit_sha":null,"homepage":"https://oxylabs.io/resources/integrations/guzzle","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxylabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-27T10:54:21.000Z","updated_at":"2025-02-11T13:00:06.000Z","dependencies_parsed_at":"2024-01-09T17:30:38.420Z","dependency_job_id":"a111f652-7ff6-4e05-afbf-3b89549c25f7","html_url":"https://github.com/oxylabs/guzzle-proxy","commit_stats":null,"previous_names":["oxylabs/guzzle-proxy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fguzzle-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fguzzle-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fguzzle-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fguzzle-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxylabs","download_url":"https://codeload.github.com/oxylabs/guzzle-proxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242980783,"owners_count":20216285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["guzzle","guzzle-php-library","guzzle-proxy","php","php-framework","php-library","php-tutorial","proxy-list","proxy-list-github","proxy-rotator","proxy-site","rotating-proxy","socks5-proxy-list","socks5-server"],"created_at":"2024-11-17T02:09:05.567Z","updated_at":"2026-06-01T00:32:16.204Z","avatar_url":"https://github.com/oxylabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to Set Up Proxies in Guzzle: PHP Tutorial\n\n[![Oxylabs promo code](https://raw.githubusercontent.com/oxylabs/product-integrations/refs/heads/master/Affiliate-Universal-1090x275.png)](https://oxylabs.io/pages/gitoxy?utm_source=877\u0026utm_medium=affiliate\u0026groupid=877\u0026utm_content=guzzle-proxy-github\u0026transaction_id=102f49063ab94276ae8f116d224b67)\n\n[![](https://dcbadge.limes.pink/api/server/Pds3gBmKMH?style=for-the-badge\u0026theme=discord)](https://discord.gg/Pds3gBmKMH) [![YouTube](https://img.shields.io/badge/YouTube-Oxylabs-red?style=for-the-badge\u0026logo=youtube\u0026logoColor=white)](https://www.youtube.com/@oxylabs)\n\n## Introduction\n\nGuzzle is a PHP HTTP client meant to facilitate HTTP requests sending and integration with web services. Its simple interface allows for building query strings, streaming large uploads and downloads, and more. With Guzzle, you no longer need to bother with stream contexts, cURL options, or sockets. \n\nIn this tutorial, we’ll review each step required to set up Oxylabs’ proxies with Guzzle.\n\n## Installing Guzzle\n\nFirst, we will learn how to install Guzzle using composer. If you don't have composer installed, you can follow the below instructions to install it. \n\n### Install Composer\n\nDownload `composer` installer using the following command:\n\n```bash\nphp -r \"copy('https://getcomposer.org/installer', 'composer-setup.php');\"\n```\n\nNext, we will have to run the installer using the below command:\n\n```bash\nphp composer-setup.php\n```\n\nLastly, we will have to move the binary to PATH:\n\n```bash\nsudo mv composer.phar /usr/local/bin/composer\n```\n\n### Install Guzzle\n\nNow that we have installed `composer`, we can use it to install Guzzle in our PHP project. We can simply run the following command:\n\n```bash\ncomposer require guzzlehttp/guzzle\n```\n\nOnce we execute the above command, it will start installing the `guzzle` and its dependencies.\n\n## Integrating Proxies\n\nIn this section, we will learn how to integrate proxies with `guzzle`. \n\n**Step 1:** First, let's import the freshly installed library:\n\n```php\nrequire_once 'vendor/autoload.php';\nuse GuzzleHttp\\Client;\n```\n\n**Step 2:** Now, we can make a `GET` request by creating a `client` object:\n\n```php\n$client = new Client();\n$client-\u003erequest('GET', 'https://ip.oxylabs.io/location', \n    ['proxy' =\u003e 'http://username:password@\u003cproxy_address\u003e:\u003cport\u003e']);\n```\n\nAs you can see, we are initiating a `Client` object and then using it to send a GET request to the \u003chttps://ip.oxylabs.io/location\u003e website. We are also passing the `proxy` as an extra argument.\n\nNote: In the proxy URL, we are passing username, password, IP address, and port. You will have to replace these with your Oxylabs’ sub-user’s credentials. If the IP address is public and doesn’t require any authentication, then we can omit the username and password and send the request as below:\n\n```php\n$client = new Client(); \n$client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://\u003cproxy_address\u003e:\u003cport\u003e']); \n```\n\n## Rotating Proxies\n\nIt's also possible to use rotating proxies with Guzzle. We can do this in various ways. For example, if you have a list of IP addresses, you can simply create an array of IPs and rotate them manually using PHP programming. This can become tedious if you have to rotate a huge list of IPs.\n\nAlternatively, you can take advantage of Oxylabs’ solutions, which automatically handle all the rotations and proxy management. In the next few sections, we will see how we can integrate Oxylabs' proxies with Guzzle. \n\n### Oxylab’s residential HTTP Proxy Setup\n\nFirst, let’s set up Oxylabs' Residential HTTP proxy. Input “pr.oxylabs.io” in the HTTP proxy server and also set the port to “7777”. The code will look like this:\n\n```php\n$client = new Client();\necho($client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://username:password@pr.oxylabs.io:7777'])-\u003egetBody());\n```\n\nWe are grabbing the Body of the response and printing it using `echo`. If everything works correctly, you should see an IP address and other location data in the terminal as soon as you execute the above code. \n\n### Oxylab’s Dedicated Datacenter HTTP Proxy Setup\n\nIf you want to set the Dedicated Datacenter Proxies instead, you will have to use the specific\ndata center IP address as the Server address. And, the port must be set to `60000`\n\n```php\n$client = new Client();\n$r = $client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://username:password@192.168.2.100:60000'])\necho($r-\u003egetBody());\n```\n\nIn the above code, we are using an example IP address `192.168.2.100`. You will have to\nreplace it with your Dedicated Datacenter IP address. Also, you will have to use your Oxylabs' credentials instead of username and password.\n\n### Oxylabs Datacenter HTTP Proxy Setup\n\nFor the Datacenter Proxy, the server address will be `dc.oxylabs.io` and port\n`8000`. So the code will look like this:\n\n```php\n$client = new Client();\n$r = $client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://username:password@dc.oxylabs.io:8000'])\necho($r-\u003egetBody());\n```\n\n### Oxylab whiteListed IP proxy setup\n\nIn addition to the above methods, Oxylabs also supports whitelisting IP addresses  for specific services. Once you whitelist your IP from the Oxylabs dashboard, you can use proxies without sending credentials on each request. This not only simplifies the setup but also increases the security of your proxies since you don’t have to keep your credentials in your scripts anymore. \n\nFor example, let’s say you have whitelisted your IP address for using the Oxylabs Residential Proxies. The code that we have written earlier can be simplified and written as below:\n\n```php\n$client = new Client();\necho($client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://pr.oxylabs.io:7777'])-\u003egetBody());\n```\n\nOxylabs will automatically detect the IP address from your request and match it with the whitelisted IP and let your request pass through. The same technique can be used with Datacenter Proxies as well. Once whitelisted, you can omit the username and password for those two as well.\n\nSo for Dedicated Datacenter Proxies, the code will look like this:\n\n```php\n$client = new Client();\necho($client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://192.168.2.100:60000'])→getBody());\n```\n\nAnd, for Datacenter Proxies, it will be:\n\n```php\n$client = new Client(); \n$r = $client-\u003erequest('GET', 'https://ip.oxylabs.io/location', ['proxy' =\u003e 'http://dc.oxylabs.io:8000']) \necho($r-\u003egetBody());\n```\n\n## Conclusion\n\nAs you can see, setting up proxies in Guzzle is quite easy and worth all the benefits you get, such as no-hassle HTTP requests sending and more. To learn more about web scraping with PHP, check out this page.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fguzzle-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxylabs%2Fguzzle-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fguzzle-proxy/lists"}