How can I add custom stream context options?

You can pass custom stream context options using the stream_context key of the request option. The stream_context array is an associative array where each key is a PHP transport, and each value is an associative array of transport options.

For example, let’s say you need to customize the outgoing network interface used with a client and allow self-signed certificates.

  1. $client->request('GET', '/', [
  2. 'stream' => true,
  3. 'stream_context' => [
  4. 'ssl' => [
  5. 'allow_self_signed' => true
  6. ],
  7. 'socket' => [
  8. 'bindto' => 'xxx.xxx.xxx.xxx'
  9. ]
  10. ]
  11. ]);