Arn*_*aud 5 php proxy get-headers
为了检查URL是否是图像,我使用PHP函数get_headers。在正常情况下,它运行良好。
但是当我落后于代理服务器时,它将导致超时异常。我有同样的问题,file_put_contents但是我通过添加上下文参数解决了。但是,该get_headers函数没有类似的参数。
你知道该怎么办吗?
小智 5
使用stream_context_set_default功能。
这篇博文解释了如何使用它。这是该页面的代码。
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2692 次 |
| 最近记录: |