zero-to-prod/stream-context

A wrapper for stream_context_create()

v71.2.5 2025-01-13 00:23 UTC

This package is auto-updated.

Last update: 2025-01-23 14:16:17 UTC


README

Repo GitHub Actions Workflow Status Packagist Downloads Packagist Version GitHub repo size License Hits-of-Code

Contents

Introduction

A wrapper for the stream_context_create() method.

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

Requirements

  • PHP 7.1 or higher.

Installation

Install Zerotoprod\StreamContext via Composer:

composer require zero-to-prod/stream-context

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

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

  • 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

Contributions, issues, and feature requests are welcome! Feel free to check the 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.