Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Ideas for speeding up code?
Old 09-12-2007, 11:39 PM Ideas for speeding up code?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Hi guys,

I'm having some issues with some very slow code at this site - http://www.blotanical.com/php/express.php

PHP Code:

$query 
'SELECT bfeed, blogRSS, bAdded FROM tblBlog WHERE bfeed = 1 AND bAdded=1 AND bPicks=0';
$result=mysql_query($query);
$num=mysql_numrows($result);

$urls = Array();

for (
$n 0$n $num-1$n++) {

    
$blogRSS=mysql_result($result,$n,"blogRSS");
    
        
$urls[]=$blogRSS;
}         

$items = array();

// loop thru all urls & merge feeds into master array
foreach ( $urls as $url ) {
    
$rss fetch_rss($url);
    if (!
$rss) continue;
    
$items array_merge($items$rss->items);
    
}

// sort all items in array by date
usort($items'date_cmp');

// generate ouput array
$out = array();

foreach (
$items as $item) {
    
$href    $item['link'];
    
$title    mysql_real_escape_string(stripslashes($item['title']));
    
$desc =  strip_tags(summary($item['description'],35),'');
    
$pubdate date('D, j M Y',strtotime($item['pubdate']));
    
    
$out[] = '<div id="repost"><h3>'.$title.'</h3><h4 style="color:#ece8de;line-height:0.8px; padding-left:5px">'.$pubdate.'</h4><p>'.$desc.'</p><a href="express_pick.php?action=display&id='.$href.'&nme='.$title.'" " title="'.$title.'">[Read more]</a></div><br /> ';
}

if (
count($out) > MAX_ITEMS)
    
$out array_slice($out,0,MAX_ITEMS);

echo (
$out)
 
    
/*    ? "<ul>\n".join("\n",$out)."\n</ul>"*/
    
join("\n",$out)
    
    : 
''
blogRSS has been Indexed.
</strong>
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-12-2007, 11:54 PM Re: Ideas for speeding up code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I'm sure looping through a number of rss urls and using php to connect to each one and wait for output response would take up most of the time. It would be ideal to use some type of caching system to try to streamline this process.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-13-2007, 02:36 PM Re: Ideas for speeding up code?
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I would recommend some form of a cron to download the file required, then put that into the file (via include).
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-13-2007, 03:09 PM Re: Ideas for speeding up code?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I cant really add anything more, looks like some pretty clean code, whats your particular issues with it?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-13-2007, 09:20 PM Re: Ideas for speeding up code?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Dan, if you check out the URL you'll notice how incredibly long it takes to load.

Cheers Rogem002. I'll start having a fiddle with that idea.
scrobins is offline
Reply With Quote
View Public Profile
 
Old 09-13-2007, 10:19 PM Re: Ideas for speeding up code?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Hey Rogem002. Cheers mate - it worked and it's so quick.

However, I have a new problem and that is because I have the cron file as an include it prints this line at the top of the page: #!/usr/local/bin/php -q

Any ideas on hiding this? I'm not sure how to comment it out as I can't use either PHP or HTML to do it.
scrobins is offline
Reply With Quote
View Public Profile
 
Old 09-14-2007, 08:06 AM Re: Ideas for speeding up code?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i just said i couldnt think of a way to speed it up other than what the other said ¬.¬ and i just re-checked it out and its still slow as hell
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-14-2007, 10:35 AM Re: Ideas for speeding up code?
Skilled Talker

Posts: 62
Name: Tom Wright
Location: Brighton, UK
Trades: 0
Could you just skip the first line when printing it?
eg start iterating at 1 instead of 0.
__________________
My site:
Please login or register to view this content. Registration is FREE
tomythius is offline
Reply With Quote
View Public Profile
 
Old 09-14-2007, 10:37 AM Re: Ideas for speeding up code?
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by scrobins View Post
Hey Rogem002. Cheers mate - it worked and it's so quick.

However, I have a new problem and that is because I have the cron file as an include it prints this line at the top of the page: #!/usr/local/bin/php -q

Any ideas on hiding this? I'm not sure how to comment it out as I can't use either PHP or HTML to do it.
It's needed I'm afraid, tells the server to run it like a PHP file. Make the CRON write the details to a file then include the file it wrote
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-15-2007, 10:41 PM Re: Ideas for speeding up code?
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Cache the page within a certain time interval so that it will automaticly recache the page as html depending on the time interval.
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 09-21-2007, 02:52 AM Re: Ideas for speeding up code?
Novice Talker

Posts: 9
Trades: 0
I don't know exactly what you want to do but id say if you want it to be fast you could try to change your query to get your data already in order and with a limit. The only thing that could slow the process is your loops.

it would look like this :

$query = 'SELECT bfeed, blogRSS, bAdded FROM tblBlog WHERE bfeed = 1 AND bAdded=1 AND bPicks=0 ORDER by `date_cmp` LIMIT MAX_ITEMS ';
Bakunin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Ideas for speeding up code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35133 seconds with 12 queries