全球VPS大学 大佬有话说 :
帮忙看看这个PHP该咋改
本帖最后由 全球VPS大学 于 2020-2-27 11:52 编辑
原贴地址:https://www.hostloc.com/thread-649304-1-1.html
感谢@yisuo 大佬帮忙写的这个PHP
需要:用这个PHP可以批量检测 this.txt里面的url链接,检测完以后会自动删除失效的。
因为这个http://127.0.0.1/api.php?url=这个接口有时间限制,每7秒只能访问一次。
所以想把这个PHP改一下,让他每7秒钟按顺序用接口检测this.txt里面的url
$url = ‘http://127.0.0.1/api.php?url=’ . $v;
到最后一个结束停止。
该怎么改。下面是大佬原来写的。
<?php
$fn = ‘this.txt’;
set_time_limit(0);
$str = @file_get_contents($fn);
if($str === false) die("return false, can’t get data from the file .");
$array = explode("rn",$str);
$new_str = ”;
foreach($array as $v){
if(empty($v)) continue;
$url = ‘http://127.0.0.1/api.php?url=’ . $v;
$refer = $url;
$ua = ‘Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36’;
$option = array(‘http’ => array(‘header’ => "Referer:$referrn" .
"user_agent:$uarn"));
$json = @file_get_contents($url, false, stream_context_create($option));
if($json === false){
echo "Error connecting to the url rn";
continue;
}
# {"status":1,"msg":"OK"}
$json2array = json_decode($json, true);
if(empty($json2array[‘status’])) continue;
if($json2array[‘status’] !== 1) continue;
else $new_str .= $v . "rn";
}
file_put_contents($fn . ‘.1’, trim($new_str));
echo "It is all done";
复世姬凌 大佬有话说 :
sleep(7)
安好 大佬有话说 :
在 for 里面加个 sleep(7);
全球VPS大学 大佬有话说 :
安好 大佬有话说 : 2020-2-27 12:05
在 for 里面加个 sleep(7);
加在哪里呢,能不能截个一小段放在的位置
安好 大佬有话说 :
全球VPS大学 大佬有话说 : 2020-2-27 12:08
加在哪里呢,能不能截个一小段放在的位置
for 里面 随便哪里
大米 大佬有话说 :
<?php
$fn = ‘this.txt’;
set_time_limit(0);
$str = @file_get_contents($fn);
if($str === false) die("return false, can’t get data from the file .");
$array = explode("rn",$str);
$new_str = ”;
foreach($array as $v){
if(empty($v)) continue;
$url = ‘http://127.0.0.1/api.php?url=’ . $v;
$refer = $url;
$ua = ‘Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36’;
$option = array(‘http’ => array(‘header’ => "Referer:$referrn" .
"user_agent:$uarn"));
$json = @file_get_contents($url, false, stream_context_create($option));
sleep(7);
if($json === false){
echo "Error connecting to the url rn";
continue;
}
# {"status":1,"msg":"OK"}
$json2array = json_decode($json, true);
if(empty($json2array[‘status’])) continue;
if($json2array[‘status’] !== 1) continue;
else $new_str .= $v . "rn";
}
file_put_contents($fn . ‘.1’, trim($new_str));
echo "It is all done";
全球VPS大学 大佬有话说 :
安好 大佬有话说 : 2020-2-27 12:09
for 里面 随便哪里
foreach($array as $v){
sleep(7);
if(empty($v)) continue;
$url = ‘http://127.0.0.1/api.php?url=’ . $v;
$refer = $url;
这样就可以了吗
全球VPS大学 大佬有话说 :
大米 大佬有话说 : 2020-2-27 12:10
谢谢ok