Php 批量位创建器
我正在尝试使bulk.ly变短,从txt文件中读取链接列表并输出缩短的链接 问题是我不知道怎么做,如果链接太快,bit.ly会有api限制。我发现,如果你一秒钟做5个链接,它应该是有效的 如何一次缩短1200个链接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
<?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();
?>