I'm in a webhosting shared-account and the max_execution_time is 120 default. i set it on set_time_limit(0) and nothing happens in the phpinfo(). Is there a way to prevent or stop the gateway timeout error before it appears? Like stop the process right away before the 504 gateway error popups. I'm fetching icons in 50 to 100 urls. Here is my line of code.
<?php
set_time_limit(0);
error_reporting(E_ERROR | E_PARSE);
include_once('../simplehtmldom_1_9_1/simple_html_dom.php');
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
function getfavicon($filename) {
libxml_use_internal_errors(false);
header('Content-type: text/html; charset=utf-8');
$file = file_get_contents($filename);
$dom = new DOMDocument;
$fav = array();
@$dom->loadHTML($file);
foreach($dom->getElementsByTagName('link') as $lnk)
{
if(($lnk->getAttribute("rel") == "icon")||($lnk->getAttribute("rel") == "shortcut icon"))
{
$fav[] = $lnk->getAttribute("href");
}
}
return $fav;
}
$servername = "localhost:3306";
$username = "topswis7_user";
$password = "J75vsHs8p6";
$database = "topswis7_scrape";
$conn = new mysqli($servername, $username, $password, $database);
$site = $_POST['favurl'];
$ids = explode("\n", str_replace("\r", "", $site));
$chunk = array_chunk($ids, 100);
$count = count($chunk);
$ficon = array();
foreach($ids as $key=>$value){
$result = parse_url($value);
$url = $result['scheme']."://".$result['host'];
// $url = 'http://example.com/';
$ch = curl_init($url);
// curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '-');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
$content = curl_exec($ch);
curl_close($ch);
// $datenbank = "proxy_work.php";
// $datei = fopen($datenbank,"w+");
// fwrite($datei, $content);
// fwrite ($datei,"\r\n");
// fclose($datei);
// echo $content;
$html = getfavicon($url);
$http = 'http';
// var_dump($html);
foreach($html as $key => $value){
$favinfo = pathinfo($value);
$check = strpos($value, $http);
// var_dump($favinfo)."<br >";
switch($favinfo['extension']){
case "ico";
if($check === false){
$value = $url."".$value;
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}else{
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}
break 2;
case "png";
if($check === false){
$value = $url."".$value;
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}else{
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}
break 2;
case "jpg";
if($check === false){
$value = $url."".$value;
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}else{
$sql = "INSERT INTO tbl_favicon(faviconLink)
VALUES ('".$value."')";
$conn->query($sql);
}
break 2;
}
}
}
$wordquery = "SELECT * FROM tbl_favicon";
$result = $conn->query($wordquery);
while($row = $result->fetch_assoc()) {
echo $row['faviconLink']."<br />";
}
echo '<br /><a href="../index.php">Back Home</a><br />
</body></html>';
// var_dump($ficon);
?>