Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在处理ID列表中的URL_Php_Macos_Curl - Fatal编程技术网

Php 正在处理ID列表中的URL

Php 正在处理ID列表中的URL,php,macos,curl,Php,Macos,Curl,我希望访问大量的URL地址,其中一部分URL是固定的,另一部分URL是可变的。更具体地说,变量始终是查询字符串 下面是URL格式的一个示例。这是因为目标URL是一个基于整数执行任务的脚本,但我有大量的“id”值要通过。我在一个文本文件中准备好了“id”值,一个值低于另一个值(因此,单独的行) 在此之前,我已经尝试过命令行、Apple脚本和curl 我的卷曲脚本如下 <?php $lines = file('input/threads.txt'); foreach($lines as

我希望访问大量的URL地址,其中一部分URL是固定的,另一部分URL是可变的。更具体地说,变量始终是查询字符串

下面是URL格式的一个示例。这是因为目标URL是一个基于整数执行任务的脚本,但我有大量的“id”值要通过。我在一个文本文件中准备好了“id”值,一个值低于另一个值(因此,单独的行)

在此之前,我已经尝试过命令行、Apple脚本和curl

我的卷曲脚本如下

<?php

$lines = file('input/threads.txt');

foreach($lines as $line)
{
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL,'http://www.example.com/thread.php?id=' . $line . '');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_exec($ch);
    curl_close($ch);
    }
?>

我想知道是否有更有效的方法来完成这项任务。我特别想知道任务的状态(‘列表下有多远…’)


谢谢,

您可以使用迭代索引作为流程指示器:

$lines = file('input/threads.txt');
$lineCount = count($lines);

foreach ($lines as $index => $line) {
    echo 'fetching URL #' . ($index + 1) . ' of ' . $lineCount . "...\n";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/thread.php?id=' . urlencode($line));
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_exec($ch);
    curl_close($ch);
}

您可以使用fopen或readfile,正如您在中所看到的,我认为您需要一些AJAX来实现这一点。。。