2013-06-14 1 views
2

URL이 이미지인지 확인하기 위해 PHP 함수 get_headers을 사용합니다. 정상적인 조건에서는 아주 잘 작동합니다.프록시가있는 get_headers 사용

하지만 프록시를 사용하고있을 때 시간 초과 예외가 발생합니다. file_put_contents과 동일한 문제가 있었지만 컨텍스트 매개 변수를 추가하여 해결했습니다. 그러나 get_headers 함수에는 비슷한 인수가 없습니다.

제발 어떻게해야할까요?

답변

2

stream_context_set_default 기능을 사용하십시오.

blog post은 사용 방법을 설명합니다. 이 페이지의 코드는 다음과 같습니다.

<?php 
// Edit the four values below 
$PROXY_HOST = "proxy.example.com"; // Proxy server address 
$PROXY_PORT = "1234"; // Proxy server port 
$PROXY_USER = "LOGIN"; // Username 
$PROXY_PASS = "PASSWORD"; // Password 
// Username and Password are required only if your proxy server needs basic authentication 

$auth = base64_encode("$PROXY_USER:$PROXY_PASS"); 
stream_context_set_default(
array(
    'http' => array(
    'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT", 
    'request_fulluri' => true, 
    'header' => "Proxy-Authorization: Basic $auth" 
    // Remove the 'header' option if proxy authentication is not required 
) 
) 
); 

$url = "http://www.pirob.com/"; 

print_r(get_headers($url)); 

echo file_get_contents($url); 
?> 
관련 문제