2012-01-25 33 views
2

我使用此解決方案:的file_get_contents

$aContext = array(
    'http' => array(
     'proxy' => 'tcp://192.168.0.2:3128', 
     'request_fulluri' => true, 
    ), 
); 
$cxContext = stream_context_create($aContext); 

$sFile = file_get_contents("http://www.google.com", False, $cxContext); 

echo $sFile; 

如何更改腳本以便不用代理,使用了格式的代理列表:

... 
192.168.0.2:3128 
193.123.8.2:3128 
194.115.10.2:80 
195.178.0.2:80 
... 

回答

2

嗯,你已經得到了大部分的代碼已經,這裏就是我想要做的:

<?php 
    $proxies = array('192.168.0.2:3128', '192.168.8.2:3128', '192.168.10.2:80'); 

    // Pick a random proxy: 
    $proxy_to_use = $proxies[ rand(0, count($proxies) -1 ]; 

    $aContext = array(
     'http' => array(
     'proxy' => 'tcp://' . $proxy_to_use, 
     'request_fulluri' => true, 
    ), 
    ); 

    $cxContext = stream_context_create($aContext); 
    $sFile = file_get_contents("http://www.google.com", False, $cxContext); 
    echo $sFile; 
?> 

是你腦子裏想的是什麼?

+0

有必要更好地解釋。我的意思是沒有意外/隨意使用。如果代理不起作用,您應該使用下列代理。如果192.168.0.2:3128'不起作用,那麼用'192.168.8.2:3128'重新... – user1168840