I am using a small module in PHP CURL which reads company name/website from the my database, generates total 9 social ranks( Alexa,facebook,Google rank,Google hit,Yahoo,Bing,Twitter,Linkedin,Google plus) for a company using social API platform link, then finally generated rank is updated in the database. Per day 3000 data are been updated in database like Mysql.
I am looking for a better way to make the process faster and update up to minimum 50000 data per day. Is there any way to make the process faster or reduce the response time ?
Is there any way to convert those script in any other language like python for obtaining my target.
Output of my script is like
Professionals{"Google_rank":0, "Google_hit":0, "Yahoo_hit":0,
"Bing_hit":0, "Alexa_rank":0, "Facebook_hit":0, "Twitter_hit":0,
"Linkedin_hit":1, "Googleplus_hit":0} Prue Jones Estate
Agents{"Google_rank":3 , "Google_hit":0, "Yahoo_hit":0, "Bing_hit":0,
"Alexa_rank":0, "Facebook_hit":0, "Twitter_hit":0, "Linkedin_hit":0,
"Googleplus_hit":0}
my script code is here:
index.php
<?php
ignore_user_abort(TRUE);
//(60 minutes * 24hrs * 2)=2days=172800
ini_set('max_execution_time', 580000); //300 seconds = 5 minutes
require("pagerank.php");
include('database.php');
error_reporting(E_ALL ^ (E_WARNING | E_NOTICE));
/*------ For China table -------*/
//$urlarray=mysql_query("select * from amt_company_china_sample order by ID");
/*------ For Australia table -------*/
$urlarray=mysql_query("select * from amt_company_aus order by company_key DESC limit 3939,2000");
echo "Updating the social rank score...<br>";
echo "Processing...<br>";
while($urlfetch=mysql_fetch_array($urlarray))
{
/*------ For China table -------*/
/*$companyid=$urlfetch['ID'];
$url=$urlfetch['WebSite'];
echo $urlname=$urlfetch['CompanyName'];*/
/*------ For Australia table -------*/
$companyid=$urlfetch['company_key'];
$url=$urlfetch['website'];
echo $urlname=$urlfetch['company_name'];
$pr = new PR();
if($url!="")
{
$active=$pr->getcheckurl($url);
$Google_rank=$pr->get_google_pagerank($url);
$Google_hit=$pr->getIndexedPagesGoogle($url);
$Yahoo_hit=$pr->getIndexedPagesYahoo($url);
$Bing_hit=$pr->getIndexedPagesBing($url);
$Alexa_rank=$pr->getAlexaRank1($url);
$Facebook_hit=$pr->getIndexedPagesFacebook($url);
$Twitter_hit=$pr->getIndexedPagesTwitter($url);
$Linkedin_hit=$pr->getLinkedInShares($urlname);
$Googleplus_hit=$pr->getGooglePlusOnes($url);
}
else
{
$active=0;
$Google_rank=0;
$Google_hit=0;
$Yahoo_hit=0;
$Bing_hit=0;
$Alexa_rank=0;
$Facebook_hit=0;
$Twitter_hit=0;
$Linkedin_hit=$pr->getLinkedInShares($urlname);
$Googleplus_hit=0;
}
echo $jsontext='{"Google_rank":'.$Google_rank.', "Google_hit":'.$Google_hit.', "Yahoo_hit":'.$Yahoo_hit.', "Bing_hit":'.$Bing_hit.', "Alexa_rank":'.$Alexa_rank.', "Facebook_hit":'.$Facebook_hit.', "Twitter_hit":'.$Twitter_hit.', "Linkedin_hit":'.$Linkedin_hit.', "Googleplus_hit":'.$Googleplus_hit.'}';
echo "<br>";
$amt_rank = 0;
$total_json_key=9;
$json_value=array($Google_rank,$Google_hit,$Yahoo_hit,$Bing_hit,$Alexa_rank,$Facebook_hit,$Twitter_hit,$Linkedin_hit,$Googleplus_hit);
for($i=0;$i<$total_json_key; $i++){
$value = $json_value[$i] == 0 ? 0.1 : $json_value[$i];
$amt_rank = $amt_rank + (1/$value);
}
/*------ For China table -------*/
/*
$result = mysql_query("UPDATE amt_company_china_sample SET rank_json='$jsontext' WHERE ID= '$companyid'");
*/
/*------ For Australia table -------*/
$result = mysql_query("UPDATE amt_company_aus SET rank_json='$jsontext',is_active='$active',amt_rank='$amt_rank' WHERE company_key= '$companyid'");
}
echo "<br>update complete...";
?>
pagerank.php
?php
class PR {
public function get_google_pagerank($url)
{
$query="http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=".$this->CheckHash($this->HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
$data=file_get_contents($query);
$pos = strpos($data, "Rank_");
if($pos === false)
{
$pagerank = "0";
return $pagerank;
}
else
{
$pagerank = substr($data, $pos + 9);
return $pagerank;
}
}
public function getIndexedPagesGoogle($url)
{
$query1 = 'http://www.google.com/search?hl=en&q=site%3A' . $url;
$data=file_get_contents($query1);
if (preg_match('#about ([0-9\,]+) results#i', $data, $p))
{
$hit=(int) str_replace(',', '', $p[1]);
return $hit;
}
return 0;
}//so on.........
Is there any solution to reduce time to collect those info or what kinds of change should i do for gaining my target.