Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

Speed up a file_get_html in jqGrid table

I have a jqGrid table that works great. I am trying to user file_get_html function to grab icons from a site and place them in table. It works fine but is taking a lot longer to load. If i remove that feature of grabbing those icons its much quicker.

Is there any way to speed that up?

Here is my function

while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { 
    $response->rows[$i]['id']=$row['activity'];

    $response->rows[$i]['cell']=array($row['app_name'],$row['activity'], '<a href=https://**.**.com/**/**/details?id=' . $row['activity'] . ' target="_blank">Link</a>' ,  '<a href='. getUrl($row['activity']) .' target="_blank"><img src='. getUrl($row['activity']) .' height="50px" width="50px"></img></a>' ,$row['count']); $i++;
} 
echo json_encode($response);

function getUrl($url){

    $html = @file_get_html("https://**.**.com/**/**/**?id=".$url);
    
    if (method_exists($html,"find")) {
        if ($html->find('html')) {
            
            foreach ($html->find('.cover-container') as $e) {
                $obj = str_get_html($e);
                foreach ($obj->find('img') as $ea) {
                    $logoImage =  $e->innertext;
                    $link= $ea->src . '<br>';
                }
            }
            $link2 = substr($link, 0, -9);
            return $link2;
        }
    }else{
        return 'http://www.***.com/****/assets/images/cancel.png';
    }

}

Open in new window


I see im using a foreach twice and there is only one cover-container. that would help by removing those foreach's? How would that look. Ive tried removing the foreach's and does work and still takes about the same amount of time to load.
0
bignadad
Asked:
bignadad
  • 2
1 Solution
 
Ray PaseurCommented:
What do you see when you use YSlow to time the various parts of the scripts?  Almost certainly, anything that slows down the process of rendering a web page will be related to HTTP latency or disk I/O.  You might want to post the Ctual URLs you are using here, so we can see what kind of responsiveness they provide.

Also, I noticed that you're using the MySQL extension.  PHP is doing away with MySQL support.  You will want to move to one of the supported extensions.  This article explains why that is happening and what you must do to keep your scripts running in the future.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
bignadadAuthor Commented:
Thanks. I'll look at yslow now.

I understand about using mysqli. I just have not updated this particular page yet.
0
 
Ray PaseurCommented:
YSlow should be able to help a lot.  It will pinpoint the most likely reasons for the slow response.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now