Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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 批量位创建器_Php_Mysql_Ajax_File Get Contents - Fatal编程技术网

Php 批量位创建器

Php 批量位创建器,php,mysql,ajax,file-get-contents,Php,Mysql,Ajax,File Get Contents,我正在尝试使bulk.ly变短,从txt文件中读取链接列表并输出缩短的链接 问题是我不知道怎么做,如果链接太快,bit.ly会有api限制。我发现,如果你一秒钟做5个链接,它应该是有效的 如何一次缩短1200个链接 <?php $sites = array( 'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e5

我正在尝试使bulk.ly变短,从txt文件中读取链接列表并输出缩短的链接

问题是我不知道怎么做,如果链接太快,bit.ly会有api限制。我发现,如果你一秒钟做5个链接,它应该是有效的

如何一次缩短1200个链接

   <?php

    $sites = array(   
    'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link2.com',
    'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link1.com',
    );

    foreach ( $sites as $site ) {
        $shortened_url = file_get_contents($site);
        if($shortened_url)
            echo "$shortened_url <br/>";
    }
    die();
    ?>

使用
sleep()
在5个链接后睡眠5秒(或API声明的秒数):


。那将是一个很大的进步,不是吗?确保每个请求之间都有足够的延迟,否则会被归类为滥用API。
<?php

$sites = array(   
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link2.com',
'http://api.bit.ly/shorten?version=2.0.1&login=bitlyexample&apiKey=R_8b726077f3d5c6029700c29e529395d3&format=text&longUrl=http://link1.com',
);
$i = 0;
foreach ( $sites as $site ) {
    $shortened_url = file_get_contents($site);
    if($shortened_url) {
        echo "$shortened_url <br/>";
    }
    $i++;
    if($i%5 == 0){
         sleep(5);
    }
}
die();
?>