To set a proxy server for Guzzle requests in PHP, you can use the request_options
parameter when making a Guzzle HTTP request. Here's a step-by-step guide:
composer require guzzlehttp/guzzle
use GuzzleHttp\Client;
$client = new Client();
$proxy = [
'http' => 'tcp://proxy.example.com:3128', // Replace with your proxy server URL and port
'https' => 'tcp://proxy.example.com:3128' // Replace with your proxy server URL and port
];
request_options
parameter when making the Guzzle request:$response = $client->request('GET', 'https://api.example.com', [
'proxy' => $proxy
]);
Now, Guzzle will send the request through the specified proxy server. Make sure to replace 'https://api.example.com'
with the actual URL you want to make the request to.
Note: Guzzle supports multiple proxy types (HTTP, SOCKS4, SOCKS4a, and SOCKS5) based on the proxy URL scheme. Adjust the proxy URL accordingly based on your proxy server type.