<?php
require __DIR__ . '/vendor/autoload.php';

// Test if the issue is specifically in web context
// by accessing localhost directly
echo "Testing localhost web request...\n";

$context = [
    'http' => [
        'method' => 'GET',
        'header' => [
            'User-Agent: Mozilla/5.0 (compatible test)',
            'Host: localhost'
        ],
        'ignore_errors' => true
    ],
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false
    ]
];

$response = @file_get_contents('https://localhost/', false, stream_context_create($context));

if ($response === false) {
    $error = error_get_last();
    echo "Failed to fetch localhost: " . $error['message'] . "\n";
    
    // Try HTTP instead
    echo "Trying HTTP instead of HTTPS...\n";
    $response = @file_get_contents('http://localhost/', false, stream_context_create($context));
    
    if ($response === false) {
        echo "HTTP also failed\n";
    } else {
        echo "HTTP response length: " . strlen($response) . "\n";
        echo "Response snippet: " . substr($response, 0, 200) . "\n";
    }
} else {
    echo "Response length: " . strlen($response) . "\n";
    echo "Response snippet: " . substr($response, 0, 200) . "\n";
}