PHPackages                             zero-to-prod/stream-context - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zero-to-prod/stream-context

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zero-to-prod/stream-context
===========================

A wrapper for stream\_context\_create()

v81.1.0(10mo ago)19801MITPHPPHP &gt;=8.1CI passing

Since Sep 1Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/zero-to-prod/stream-context)[ Packagist](https://packagist.org/packages/zero-to-prod/stream-context)[ Docs](https://github.com/zero-to-prod/stream-context)[ Fund](https://github.com/sponsors/zero-to-prod)[ RSS](/packages/zero-to-prod-stream-context/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (22)Used By (1)

Zerotoprod\\StreamContext
=========================

[](#zerotoprodstreamcontext)

[![](./art/logo.png)](./art/logo.png)

[![Repo](https://camo.githubusercontent.com/9a90a3efeee26aed7d7f2feee9cd84566a26f9c362cc773b184d076210906e1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746875622d677261793f6c6f676f3d676974687562)](https://github.com/zero-to-prod/stream-context)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/f8b77b9b8641723e186e09683ab56438a798537773b447e22f364417b3988a1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578742f746573742e796d6c3f6c6162656c3d74657374)](https://github.com/zero-to-prod/stream-context/actions)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/0b8b767d494db7420a945513ae6a1cb5da99ba5af2d4fb2b4bcd11a085a89052/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578742f6261636b77617264735f636f6d7061746962696c6974792e796d6c3f6c6162656c3d6261636b77617264735f636f6d7061746962696c697479)](https://github.com/zero-to-prod/stream-context/actions)[![Packagist Downloads](https://camo.githubusercontent.com/442a7bfe58fdd027e2b74dac7ce04c95fdcfac4bcd8d60e46f0182582dadd66b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578743f636f6c6f723d626c7565)](https://packagist.org/packages/zero-to-prod/stream-context/stats)[![Packagist Version](https://camo.githubusercontent.com/5b6527741b0e918da42bd8810a86d788fc83dec77556c042b6641854145df522/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578743f636f6c6f723d663238643161)](https://packagist.org/packages/zero-to-prod/stream-context)[![GitHub repo size](https://camo.githubusercontent.com/7f01a04418601a2a67d2c52a92a3e912cbdc44de9b683b0a0fe79a4ac488adbe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f7a65726f2d746f2d70726f642f73747265616d2d636f6e74657874)](https://github.com/zero-to-prod/stream-context)[![License](https://camo.githubusercontent.com/ed78a1a2d83a5efb7768690e9738d996aa25f2bab1645889db4a6e8b35bd0504/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578743f636f6c6f723d726564)](https://github.com/zero-to-prod/stream-context/blob/main/LICENSE.md)[![Hits-of-Code](https://camo.githubusercontent.com/df8885d0fc3fdb9da156838b469465e8685780577020deb39fe167cd4b7923f6/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f7a65726f2d746f2d70726f642f73747265616d2d636f6e746578743f6272616e63683d6d61696e)](https://hitsofcode.com/github/zero-to-prod/stream-context/view?branch=main)

Contents
--------

[](#contents)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Documentation Publishing](#documentation-publishing)
    - [Automatic Documentation Publishing](#automatic-documentation-publishing)
- [Usage](#usage)
    - [Supported Protocols](#supported-protocols)
- [Local Development](./LOCAL_DEVELOPMENT.md)
- [Contributing](#contributing)

Introduction
------------

[](#introduction)

A wrapper for the [`stream_context_create()`](https://www.php.net/manual/en/function.stream-context-create.php) method.

It provides classes that define all the options for this method.

Requirements
------------

[](#requirements)

- PHP 7.1 or higher.

Installation
------------

[](#installation)

Install `Zerotoprod\StreamContext` via [Composer](https://getcomposer.org/):

```
composer require zero-to-prod/stream-context
```

This will add the package to your project’s dependencies and create an autoloader entry for it.

Documentation Publishing
------------------------

[](#documentation-publishing)

You can publish this README to your local documentation directory.

This can be useful for providing documentation for AI agents.

This can be done using the included script:

```
# Publish to default location (./docs/zero-to-prod/stream-context)
vendor/bin/zero-to-prod-stream-context

# Publish to custom directory
vendor/bin/zero-to-prod-stream-context /path/to/your/docs
```

### Automatic Documentation Publishing

[](#automatic-documentation-publishing)

You can automatically publish documentation by adding the following to your `composer.json`:

```
{
  "scripts": {
    "post-install-cmd": [
      "zero-to-prod-stream-context"
    ],
    "post-update-cmd": [
      "zero-to-prod-stream-context"
    ]
  }
}
```

Usage
-----

[](#usage)

```
use Zerotoprod\StreamContext\StreamContext;
use Zerotoprod\StreamContext\DataModels\Options;
use Zerotoprod\StreamContext\DataModels\Http;

$client = stream_socket_client(
    'ssl://neverssl.com:443',
    $error_code,
    $error_message,
    30,
    STREAM_CLIENT_CONNECT,
    StreamContext::create([
        Options::http => [
            Http::method => 'GET',
            Http::header => "Accept-language: en\r\n"."Cookie: foo=bar",
            Http::proxy => 'proxy'
        ],
        ['options']
    ])->context
);

fclose($client);
```

### Supported Protocols

[](#supported-protocols)

- HTTP: Customize request methods, headers, user-agent, and more.
- FTP: Manage file transfers with options like overwrite, resume position, and proxy.
- SSL: Configure SSL/TLS options including peer verification, certificates, and more.
- Phar: Set options like compression and metadata for Phar archives.
- Zip: Handle encrypted Zip files with password options.
- Zlib: Control compression levels for zlib streams.

Contributing
------------

[](#contributing)

Contributions, issues, and feature requests are welcome! Feel free to check the [issues](https://github.com/zero-to-prod/stream-context/issues) page if you want to contribute.

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit changes (`git commit -m 'Add some feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a new Pull Request.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance54

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Recently: every ~54 days

Total

21

Last Release

307d ago

Major Versions

v71.x-dev → v81.0.02025-01-29

PHP version history (3 changes)v71.0.0PHP ^7.1

v71.2.4PHP &gt;=7.1

v81.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/502649f05d36c87d494988bd99193a4d908d345335d99c080928a726277371f5?d=identicon)[zero-to-prod](/maintainers/zero-to-prod)

---

Top Contributors

[![zero-to-prod](https://avatars.githubusercontent.com/u/61474950?v=4)](https://github.com/zero-to-prod "zero-to-prod (17 commits)")

---

Tags

stream contextzero-to-prod

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zero-to-prod-stream-context/health.svg)

```
[![Health](https://phpackages.com/badges/zero-to-prod-stream-context/health.svg)](https://phpackages.com/packages/zero-to-prod-stream-context)
```

###  Alternatives

[zero-to-prod/data-model

Transforms Data into Type-Safe DTOs.

14231.6k32](/packages/zero-to-prod-data-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
