无需等待每个文件加载即可继续执行循环


Continuing through loop without having to wait foreach file to load

我使用for循环来加速我的脚本。问题是,在循环内发生的每个进程都需要几分钟才能加载。如果前一个序列没有完成,是否有可能移动到循环中的下一个序列?我知道PHP不是一个多线程语言,所以也许Python会是一个更好的选择。

ini_set('memory_limit', '2048M');
ini_set('max_execution_time', 0);
$list = file_get_contents('auth.txt');
$list = nl2br($list);
$exp = explode('<br />', $list);
$count = count($exp);
for($i=0;$i<$count;$i++) {
    $auth = $exp[$i];
    echo 'Trying '.$auth.' 'n';
    // This takes several minutes. Is it possible to move on to the next one before it has completed?
    exec('python test.py --auth='.$auth);
}

使用&在后台运行脚本:

exec('python test.py --auth='.$auth . ' > /dev/null 2>&1 &');