Solved

Speed up a file_get_html in jqGrid table

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

710 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