This is a very simple script which is giving a button to some websites for Affiliate who are using Ajax/Javascript/jQuery to get there required plugin via this following code from my server. but its taking most of the site +/_ 20 seconds and other plugin's get loaded within 30ms.
I cant understand what is the part causing such slow loading? What am i doing wrong here? and how can you improve it?
<?php
header('Access-Control-Allow-Origin: *');
$customerid = $_GET['id'];
$what = $_GET['button'];
$id = substr('3' . rand(0,9999), 0-$length);
switch ($customerid) {
case 'customer1':
break;
case 'customer2':
break;
default:
$da = "https://server0/1.php?r={$id}&endof=end";
$db = "https://server1?r={$id}";
$imagelink = "http://server2.com:8080/images/button.png";
$a = "<a href={$da} id={$} class={$customerid}abutton onclick=\"typeof(_gaq)=='undefined'?'':_gaq.push(['_trackEvent', 'Mycompany', 'ButtonClick']);typeof(_gat)=='undefined'?'':_gat._getTrackerByName()._setAllowLinker(true); window.open(typeof(_gat)=='undefined'?this.href+'?referrer='+escape(window.location.href):_gat._getTrackerByName()._getLinkerUrl(this.href+'?referrer='+escape(window.location.href)), '_blank', 'width=480,height=360,resizable=no,toolbar=no,menubar=no,location=no,status=no'); return false\"><img src=\"{$imagelink}\" /></a>";
$b = "<a href={$db} id={$} class={$customerid}aabutton onclick=\"typeof(_gaq)=='undefined'?'':_gaq.push(['_trackEvent', 'Mycompany', 'ButtonClick']);typeof(_gat)=='undefined'?'':_gat._getTrackerByName()._setAllowLinker(true); window.open(typeof(_gat)=='undefined'?this.href+'?referrer='+escape(window.location.href):_gat._getTrackerByName()._getLinkerUrl(this.href+'?referrer='+escape(window.location.href)), '_blank', 'width=480,height=360,resizable=no,toolbar=no,menubar=no,location=no,status=no'); return false\"><img src=\"{$imagelink}\" /></a>";
$section = file_get_contents("http://server2/ajax/getstatus");
$section = json_decode($section);
if ($section->result){
switch($what) {
case 'v':
echo $b;
break;
case 'a':
echo $a;
break;
case 'b':
echo $a . $b;
break;
}
} else {
switch($what) {
case 'v':
break;
case 'a':
echo $a;
break;
case 'b':
echo $a;
break;
}
}
break;
}
?>
Get status: taking the most duration , what can i do to optimize it? taking almost 10 second on this.
public function getstatusAction() {
$this->_response->setHeader('Access-Control-Allow-Origin', '*');
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$post = $this->getRequest()->getQuery();
$data = (object) $post;
$this->db = Application_Model_Db::db_load();
$sql = "select *from sh_av_users where
status='online'
limit 1";
$result = $this->db->fetchAll($sql);
if (count($result) > 0) {
$json = array(
'result' =>true,
);
} else {
$json = array(
'result' =>false,
);
}
$content = Zend_Json::encode($json);
$this->getResponse()
->setHeader('Content-Type', 'application/json')
->setBody($content)
->sendResponse();
exit;
}