Solved

Speed up a file_get_html in jqGrid table

Posted on 2014-09-08
3
365 Views
Last Modified: 2014-09-15
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
Comment
Question by:bignadad
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40310322
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
 
LVL 2

Author Comment

by:bignadad
ID: 40310343
Thanks. I'll look at yslow now.

I understand about using mysqli. I just have not updated this particular page yet.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40310591
YSlow should be able to help a lot.  It will pinpoint the most likely reasons for the slow response.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question