Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2010, 09:37 AM
NexDog's Avatar
NexDog NexDog is offline
 
Join Date: Mar 2002
Location: Lost in the Nexus
Posts: 388
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP include triggers HTTP cascade

I followed this:

http://www.vbulletin.com/forum/showt...P-or-HTML-File

And created a Plugin with:

PHP Code:
ob_start();
   include(
'/path/to/forum/wordpress.php');
   
$includeVP ob_get_contents();
ob_end_clean(); 
wordpress.php is a file that calls SimplePie and pulls a feed from our blog and displays titles of the last 5 blog posts in the footer.

This is the code:

PHP Code:
<?php
 
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('/home/httpd/vhosts/domain.com/httpdocs/include/simplepie.inc');
require_once(
'/home/httpd/vhosts/domain.com/httpdocs/include/shorten.inc');

// We'll process this feed with all of the default options.
$feed = new SimplePie();
$feed->set_feed_url(array('http://www.domain.com/forum/external.php?type=rss'));
//$feed->set_feed_url(array('http://www.domain.com/blog/category/status/feed/'));
$feed->init();
$feed->set_item_limit(5);
 
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
 
// Let's begin our XHTML webpage code.  The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.

/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items() as $item):
?>
<tr>
    <td align="left" width="13"><img src="../../../../images/site/thread.gif"></td>
    <td align="left" width="100%"><a class="feeds" href="<?php echo $item->get_permalink(); ?>"><?php echo shorten($item->get_title(), 35); ?></a><br /></td>
</tr>
<?php endforeach; ?>
shorten.inc is some extra code that shortens the char limit of the displayed title to 35 characters.

Problem is when I refresh the page it spawns hundreds of httpd process in a loop that raises loads to 150+.

Anyone have any ideas to what I'm doing wrong?

I use teh same code to pull vbulletin titles to our blog footer and rest of the site, and wordpress titles to its own footer and other areas of the site. On VB it just goes ballistic.

--------------- Added [DATE]1279536057[/DATE] at [TIME]1279536057[/TIME] ---------------

Actually it was the vbulletin.php containing code that pulled titles from vBulletin that caused teh loop. I activated teh wordpress.php plugin and the server is fine. However it doesn't display anything.
Reply With Quote
  #2  
Old 07-19-2010, 12:33 PM
Guest190829
Guest
 
Posts: n/a
Default

I don't know why I've seen people in the habit of manually capturing an external PHP output rather than just putting the PHP code in the hook:

1.) Adapt and add the following code to Hook: parse_templates

PHP Code:
require_once('SimplePie/simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('https://vborg.vbsupport.ru/external.php?type=RSS2');
$feed->init();

$feed->handle_content_type();

$feed_html '';

foreach(
$feed->get_items() AS $item)
{
   
$feed_html .= '<p><a href="' $item->get_permalink() .'">' $item->get_title() . '</a></p>';


2.) Place variable $feed_html into the footer variable where you wish.

and voila! None of this nasty ob_start() and ob_end() stuff, it's unnecessary!

Adapt the code to your liking, I even used SimplePie for you. You'll want to edit the include director, the feed url, and probably make the formatting of $feed_html a little nicer.
Reply With Quote
  #3  
Old 07-19-2010, 01:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Danny.VBT View Post
I don't know why I've seen people in the habit of manually capturing an external PHP output rather than just putting the PHP code in the hook:
Well, for one thing there's an example of how to do it in the vBulletin manual, and not everyone's a PHP programmer. But also if it's existing code or something obtained elsewhere, altering a copy of it can create a maintenance issue.
Reply With Quote
  #4  
Old 07-19-2010, 01:12 PM
NexDog's Avatar
NexDog NexDog is offline
 
Join Date: Mar 2002
Location: Lost in the Nexus
Posts: 388
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm, also caused the server to crash.
Reply With Quote
  #5  
Old 07-19-2010, 01:24 PM
Guest190829
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by kh99 View Post
Well, for one thing there's an example of how to do it in the vBulletin manual, and not everyone's a PHP programmer. But also if it's existing code or something obtained elsewhere, altering a copy of it can create a maintenance issue.
Do you have a link to where it is in the manual ?

Quote:
Originally Posted by NexDog View Post
Hmm, also caused the server to crash.
I need more information to see what wrong. I ran this on my test server with no problems.
Reply With Quote
  #6  
Old 07-19-2010, 01:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Danny.VBT View Post
Do you have a link to where it is in the manual ?
http://www.vbulletin.com/docs/html/m..._externalfiles

Just to be clear, I'm not saying that it's always the best thing to do just because it's in the manual, I'm just saying that's probably one reason you see it so much.

But I'm not a PHP expert - maybe you could elaborate on why you consider ob_start/ob_end "nasty".


ETA: BTW, my guess would be that the above is crashing because this line

PHP Code:
require_once('SimplePie/simplepie.inc'); 
has the wrong path to the include file. But it's just a guess.
Reply With Quote
  #7  
Old 07-19-2010, 01:51 PM
Guest190829
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by kh99 View Post
http://www.vbulletin.com/docs/html/m..._externalfiles

Just to be clear, I'm not saying that it's always the best thing to do just because it's in the manual, I'm just saying that's probably one reason you see it so much.

But I'm not a PHP expert - maybe you could elaborate on why you consider ob_start/ob_end "nasty".


ETA: BTW, my guess would be that the above is crashing because this line

PHP Code:
require_once('SimplePie/simplepie.inc'); 
has the wrong path to the include file. But it's just a guess.
Well, in my opinion, it adds an additional (and often unnecessary) layer of overhead and muddles transparency.

I think forum owners are using it as a quick means to modify their forums without understanding exactly what they are doing and how it works.

The manual states "Including external files," but I am seeing people create external files just to use that generalized snippet of code.
Reply With Quote
  #8  
Old 07-19-2010, 01:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Danny.VBT View Post
The manual states "Including external files," but I am seeing people create external files just to use that generalized snippet of code.
Ah, I see. That makes sense. Carry on.
Reply With Quote
  #9  
Old 07-20-2010, 02:55 AM
NexDog's Avatar
NexDog NexDog is offline
 
Join Date: Mar 2002
Location: Lost in the Nexus
Posts: 388
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think I'll just give teh job to someone that understands vbulletin and php better than I (which is everyone over teh age of 3).
Reply With Quote
  #10  
Old 07-20-2010, 10:12 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by NexDog View Post
I think I'll just give teh job to someone that understands vbulletin and php better than I (which is everyone over teh age of 3).
Well that's up to you of course, but don't let our side discussion discourage you. There's really nothing wrong with doing it either way, IMHO.

You could add some HTML comments to the output to see what's happening (e.g. is it not displaying because there's nothing for the foreach loop to do, or is it never getting there?).
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 07:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04092 seconds
  • Memory Usage 2,276KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (7)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete