Solved

Speed up a file_get_html in jqGrid table

Posted on 2014-09-08
3
367 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 110

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 110

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

685 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