Php 文件获取代理背后的内容(使用代理列表)

Php 文件获取代理背后的内容(使用代理列表),php,proxy,file-get-contents,Php,Proxy,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",

我使用这个解决方案:

$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
...

好吧,您已经获得了大部分代码,下面是我要做的:

<?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);
    $content = file_get_contents("http://www.google.com", false, $cxContext);

    echo $content;
?>


这就是你的想法吗?

有必要更好地解释。我的意思是没有意外/随意使用。如果代理不起作用,则应使用以下代理。如果192.168.0.2:3128'不起作用,则用'192.168.8.2:3128'进行报告。。。