Solved

Speed up a file_get_html in jqGrid table

Posted on 2014-09-08
3
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 invoke it on a web page. 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.: (CODE)

631 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