SE_Danny Posted April 18, 2011 Share Posted April 18, 2011 Hi guys !I have a simple php script that saves a webpage in my database, and looks for a thumbnail for it.Here's the code :The problem is, it's extremely slow.How can I make that much faster ? <?php$message = "saving bookmark ... please wait.";include "functions.php";if(!loggedin()){ header("Location: ../index.php"); exit();}else{$title = mysql_real_escape_string($_POST['Title']);$site = mysql_real_escape_string($_POST['Url']);$num = $_POST['num'];$p = $_GET['p']; if($title&&$site&&$num){ switch (true) { case stristr($site,'.png'): $thumbsite = "$site|||/Logos/png.jpg"; break; case stristr($site,'.jpg'): $thumbsite = "$site|||/Logos/jpg.jpg"; break; case stristr($site,'.gif'): $thumbsite = "$site|||/Logos/gif.jpg"; break; case stristr($site,'.pdf'): $thumbsite = "$site|||/Logos/pdf.jpg"; break; case stristr($site,'google'): $thumbsite = "$site|||/Logos/google.jpg"; break; case stristr($site,'apple'): $thumbsite = "$site|||/Logos/apple.jpg"; break; case stristr($site,'gmail') || stristr($site,'mail.google'): $thumbsite = "$site|||/Logos/gmail.jpg"; break; case stristr($site,'yahoo'): $thumbsite = "$site|||/Logos/yahoo.jpg"; break; case stristr($site,'redbull'): $thumbsite = "$site|||/Logos/redbull.jpg"; break; case stristr($site,'youtube'): $thumbsite = "$site|||/Logos/youtube.jpg"; break; case stristr($site,'vimeo'): $thumbsite = "$site|||/Logos/vimeo.jpg"; break; case stristr($site,'hotmail') || stristr($site,'login.live'): $thumbsite = "$site|||/Logos/hotmail.jpg"; break; case stristr($site,'facebook'): $thumbsite = "$site|||/Logos/facebook.jpg"; break; case stristr($site,'3run'): $thumbsite = "$site|||/Logos/3run.jpg"; break; case stristr($site,'free.fr'): $thumbsite = "$site|||/Logos/free.jpg"; break; case stristr($site,'ivy'): $thumbsite = "$site|||/Logos/ivy.jpg"; break; case stristr($site,'twitter'): $thumbsite = "$site|||/Logos/twitter.jpg"; break; case stristr($site,'bbc'): $thumbsite = "$site|||/Logos/bbc.jpg"; break; case stristr($site,'flickr'): $thumbsite = "$site|||/Logos/flickr.jpg"; break; case stristr($site,'wikipedia'): $thumbsite = "$site|||/Logos/wikipedia.jpg"; break; case stristr($site,'amazon'): $thumbsite = "$site|||/Logos/amazon.jpg"; break; case stristr($site,'koreus'): $thumbsite = "$site|||/Logos/koreus.jpg"; break; case stristr($site,'bing'): $thumbsite = "$site|||/Logos/bing.jpg"; break; case stristr($site,'leica'): $thumbsite = "$site|||/Logos/leica.jpg"; break; case stristr($site,'deezer'): $thumbsite = "$site|||/Logos/deezer.jpg"; break; case stristr($site,'ebay'): $thumbsite = "$site|||/Logos/ebay.jpg"; break; case stristr($site,'imdb'): $thumbsite = "$site|||/Logos/imdb.jpg"; break; case stristr($site,'mozilla'): $thumbsite = "$site|||/Logos/mozilla.jpg"; break; case stristr($site,'myspace'): $thumbsite = "$site|||/Logos/myspace.jpg"; break; case stristr($site,'nytimes'): $thumbsite = "$site|||/Logos/nytimes.jpg"; break; case stristr($site,'baidu'): $thumbsite = "$site|||/Logos/baidu.jpg"; break; case stristr($site,'blogger') || stristr($site,'blogspot'): $thumbsite = "$site|||/Logos/blogger.jpg"; break; case stristr($site,'linkedin'): $thumbsite = "$site|||/Logos/linkedin.jpg"; break; case stristr($site,'microsoft'): $thumbsite = "$site|||/Logos/microsoft.jpg"; break; case stristr($site,'msn'): $thumbsite = "$site|||/Logos/msn.jpg"; break; case stristr($site,'wordpress'): $thumbsite = "$site|||/Logos/wordpress.jpg"; break; case stristr($site,'tpg.ch'): $thumbsite = "$site|||/Logos/tpg.jpg"; break; case stristr($site,'Red-Bull-Web-TV'): $thumbsite = "$site|||/Logos/redbulltv.jpg"; break; case stristr($site,'about.com'): $thumbsite = "$site|||/Logos/about.jpg"; break; case stristr($site,'cern.ch'): $thumbsite = "$site|||/Logos/cern.jpg"; break; case stristr($site,'cnet.com'): $thumbsite = "$site|||/Logos/cnet.jpg"; break; case stristr($site,'cnn'): $thumbsite = "$site|||/Logos/cnn.jpg"; break; case stristr($site,'doubleclick'): $thumbsite = "$site|||/Logos/doubleclick.jpg"; break; case stristr($site,'espn'): $thumbsite = "$site|||/Logos/espn.jpg"; break; case stristr($site,'leo.org'): $thumbsite = "$site|||/Logos/leo.jpg"; break; case stristr($site,'mediafire'): $thumbsite = "$site|||/Logos/mediafire.jpg"; break; case stristr($site,'orkut'): $thumbsite = "$site|||/Logos/orkut.jpg"; break; case stristr($site,'thepiratebay'): $thumbsite = "$site|||/Logos/thepiratebay.jpg"; break; case stristr($site,'tumblr'): $thumbsite = "$site|||/Logos/tumblr.jpg"; break; case stristr($site,'jeuxvideo'): $thumbsite = "$site|||/Logos/jeuxvideo.jpg"; break; case stristr($site,'zapiks'): $thumbsite = "$site|||/Logos/zapiks.jpg"; break; case stristr($site,'youporn'): $thumbsite = "$site|||/Logos/youporn.jpg"; break; case stristr($site,'redtube'): $thumbsite = "$site|||/Logos/redtube.jpg"; break; case stristr($site,'apptrackr'): $thumbsite = "$site|||/Logos/apptrackr.jpg"; break; case stristr($site,'sina.com'): $thumbsite = "$site|||/Logos/sina.jpg"; break; case stristr($site,'qq.com'): $thumbsite = "$site|||/Logos/qq.jpg"; break; default: $thumbsite = "$site|||/Logos/default.jpg"; break; } $titlex = "title$num"; $sitex = "site$num"; $query = mysql_query("UPDATE user SET $titlex='$title' , $sitex='$thumbsite' WHERE username='$printuser' ") or die("Could not change"); header("Location: ../user.php?p=$p"); exit(); }else $message = "Please enter a url"; // end site&&code check} // end loggedin?> Thanks !! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2011 Share Posted April 18, 2011 You can use the microtime function to figure out what is taking the most time.http://www.php.net/manual/en/function.microtime.phpe.g.: $start_time = microtime(true);// do some stuffecho 'line ' , __LINE__ , ': ' , (microtime(true) - $start_time); Save the time when the script starts, then you can add that other line where ever you want to print the line number it's on and how much time has elapsed since the script started.The redirect header won't work with the output, but once you figure out where the problem is you can remove those statements. Link to comment Share on other sites More sharing options...
SE_Danny Posted April 18, 2011 Author Share Posted April 18, 2011 You can use the microtime function to figure out what is taking the most time.Save the time when the script starts, then you can add that other line where ever you want to print the line number it's on and how much time has elapsed since the script started.The redirect header won't work with the output, but once you figure out where the problem is you can remove those statements.Ok Thank you ! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.