0
I’m having trouble checking with remote files, the structure is as follows:
function endereco_existe($url) {
$h = get_headers($url);
$status = array();
preg_match('/HTTP\/.* ([0-9]+) .*/', $h[0] , $status);
$result = $status[1];
if($result == "200")
{
return true;//verdadeiro
}else
{
return false;//falso
}
}
this function works perfectly ,however what happens when I call this function often makes the page very slow and even does not open , I did the test taking this function and the problem does not appear,
this function is used in this context:
function lista($ini,$fin,$url,$ext,$op=0,$stp=1)
{
echo "<p id='rep'></p>";
echo "<script>function rep(url,i){var t = '<style>div.img{position: relative; width: 100%;}div.img > img{position: absolute; right: 3%; margin-right: 0px; top: 4%; margin-top: 0px; background-color: ; width:12%;opacity: 0.2; filter: alpha(opacity=20);}</style><div style=text-align:center; id=top>Lista '+i+'</div><div style=text-align:right;><a href=javascript:void(0); onclick=fechar();>[Fechar]</a></div><div class=img><video width=100% controls><source src='+url+' type=video/mp4>Seu Navegador não Suporta Repoduzir esse video baixe o Firefox ou Google Chrome</video><img src=logo.png></div>';document.getElementById('rep').innerHTML = t;} function fechar(){document.getElementById('rep').innerHTML =' ';}</script>";
for($i=$ini;$i<=$fin;$i++)
{
if($i<10)
{
$i = "0".$i;
}
if($stp==1)
{
if(endereco_existe($url.$i.$ext)==false)
{ break;}
}
echo "Lista 1".($i-$op)." ";
echo "<a href='#top' onclick='rep(`".$url.$i.$ext."`,".($i-$op).")'>Repoduzir</a>";
echo " | ";
echo "<a download='Lista ".$i.".mp4' href='".$url.$i.$ext."' target='_blank'>Baixar</a>";
echo "<br />";
}
}
It lists some videos, passed to the function that are listed by the suffix 01,02 and so on that are determined in "for" (www.examplo.com/video01.mp4), I wonder if there is any solution in this check if the file exists and in the listing of the same?
you make a request with Curl on
get_headers()
?– rray
So I used the Curl already and continued slow to check.
function curl_info($url){
 $ch = curl_init();
 curl_setopt( $ch, CURLOPT_URL, $url );
 curl_setopt( $ch, CURLOPT_HEADER, 1);
 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 0 );
 curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
 $content = curl_exec( $ch );
 $info = curl_getinfo( $ch );
 return $info;
 }
– ThiagoCI
You are not checking the existence of files, you are checking Urls, each different url access takes some time, imagine multiple checks of different web pages.
– Guilherme Nascimento