Why is my code slow, if I remove all stuff to get those meta tags the code becomes super fast, I don't know OOP though.
It was pretty good after I added it the functionality to get meta tags from a URL. I don't know if SQL is making it slow, or the get_meta_tags function.
<?php
$servername = "localhost";
$username = "phpmyadmin";
$password = "supersu";
$starttime = time();
function cape($url,$depth=5) {
if($depth>0) {
$html = file_get_contents($url);
$pattern = '~<a.*?href="(.*?)".*?>~';
preg_match_all($pattern, $html, $matches);
foreach($matches[1] as $newurl) {
// do stuff
$regex = "((https?|ftp)\:\/\/)?";
// SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
// User and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,3})";
// Host or IP
$regex .= "(\:[0-9]{2,5})?";
// Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?";
// Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?";
// GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?";
// Anchor
// `i` flag for case-insensitive
if(preg_match("/^$regex$/i", $newurl)) {
if(substr($newurl, -1) !== "/") {
$newurl = $newurl . "/";
}
try {
$tags = get_meta_tags($newurl);
$desc = file_get_contents($newurl);
$password = "supersu";
$username = "phpmyadmin";
$conn = new PDO("mysql:host=localhost;dbname=supersu", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($tags['description'])) {
$conn->exec( 'INSERT INTO snapd (link,Description) SELECT * FROM (SELECT "'.$newurl.'","'.$tags['description'].'") AS tmp WHERE NOT EXISTS ( SELECT link FROM snapd WHERE link = "'.$newurl.'" ) LIMIT 1' );
echo $newurl;
} else {
$conn->exec( 'INSERT INTO snapd (link,Description) SELECT * FROM (SELECT "'.$newurl.'","No Info") AS tmp WHERE NOT EXISTS ( SELECT link FROM snapd WHERE link = "'.$newurl.'" ) LIMIT 1' );
echo $newurl;
}
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
cape($newurl,$depth-1);
}
}
}
}
cape("https://techdeploy.xyz");
?>