padraic/humbug_get_contents
Drop-in replacement for file_get_contents() that secures HTTPS requests on PHP 5.3+ by injecting a strict SSL/TLS stream context (CA validation, verification). Helps prevent MITM attacks when fetching APIs, PHARs, or other remote content.
Install the package via Composer to add a secure HTTPS wrapper around file_get_contents():
composer require padraic/humbug_get_contents
Begin by replacing existing file_get_contents() calls that target HTTPS URLs with Humbug\get_contents()—no config needed. This is most valuable when maintaining legacy PHP <5.6 applications (e.g., WordPress plugins, old Laravel 4/5 apps on PHP 5.4–5.5) where SSL verification is disabled by default. Example first use case: fetching a JSON API response securely in a deployment script or CLI tool:
use Humbug\get_contents;
$apiData = get_contents('https://status.example.com/health.json');
$data = json_decode($apiData, true);
file_get_contents() is used for HTTPS—especially when upgrading PHP is blocked. No code refactoring beyond the function call is required.humbug/box) where lightweight, secure HTTP fetching is needed without external dependencies.set_headers() applies only to the next call, set headers just before get_contents() in tight scopes:
Humbug\set_headers([
'Authorization: Bearer ' . $this->token,
'Accept: application/json'
]);
$response = Humbug\get_contents('https://api.secure.com/v1/data');
$content = Humbug\get_contents($url);
$headers = Humbug\get_headers(); // Returns array like ['Content-Type: application/json', ...]
runkit_function_redefine() or runtime prefixing). Prefer mocking dependencies at the class level where possible.Humbug\get_contents() is already declared (e.g., from another package), it will skip redeclaration silently. Use composer require --with-all-dependencies and ensure no other dependencies pull in a conflicting fork.Failed to enable crypto or verify failure mean certificate verification failed. Don’t suppress with @ or disable verify_peer. Fix the root cause: install/update CA bundle (ca-certificates package), or configure openssl.cafile/openssl.capath in php.ini.set_headers() does not persist—call it before every get_contents() that needs custom headers. Forgotten headers cause subtle auth failures.stream_context, which lacks HTTP/2 support and advanced features (pipelining, trailers, retry logic).Function Humbug\set_headers is deprecated. Suppressing them is discouraged—plan to remove this dependency during PHP/HTTP-stack modernization.hash_equals() on signatures, PHAR verification).How can I help you explore Laravel packages today?