PHP-代理检查器多线程

时间:2018-11-21 12:03:24

标签: php multithreading proxy

我已经使用php制作了我的个人单线程代理检查器,但是我无法将其设置为多线程,几天前,我在github上发现了一个使用多线程的检查器,有人可以帮助更改它以保存好代理放入文件(ip:port格式)?

https://raw.githubusercontent.com/samuel-allan/FastProxyChecker/master/checker.php

我尝试过的事情:

original line 91:
echo json_encode($arr);

changed to:

$json = json_decode($arr);
$good_proxie = $json['arr']['result']['proxy']['ip'];
echo "$good_proxie";

1 个答案:

答案 0 :(得分:0)

我没有检查它,但是认为它可以工作^ _ ^

function CheckMultiProxy($proxies, $timeout, $proxy_type)
{
    $data = array();
    foreach($proxies as $proxy)
    {
        $parts = explode(':', trim($proxy));
        $url = strtok(curPageURL(),'?');
        $data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;
    }
    $results = multiRequest($data);
    $holder = array();
    foreach($results as $result)
    {

        $holder[] = json_decode($result, true)["result"];
    }
    $arr = array("results" => $holder);

    foreach ($arr['results'] as $proxy) {
        if ($proxy['success']) {
           file_put_contents('YOUR_FILE_HERE', $proxy['proxy']['ip'].':'.$proxy['proxy']['port'].' '.$proxy['proxy']['type'].PHP_EOL, FILE_APPEND);
        }
    }

    echo json_encode($arr);
}