vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PHP include triggers HTTP cascade (https://vborg.vbsupport.ru/showthread.php?t=246873)

NexDog 07-19-2010 09:37 AM

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.

Guest190829 07-19-2010 12:33 PM

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.

kh99 07-19-2010 01:08 PM

Quote:

Originally Posted by Danny.VBT (Post 2071492)
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.

NexDog 07-19-2010 01:12 PM

Hmm, also caused the server to crash. :)

Guest190829 07-19-2010 01:24 PM

Quote:

Originally Posted by kh99 (Post 2071510)
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 (Post 2071512)
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.

kh99 07-19-2010 01:30 PM

Quote:

Originally Posted by Danny.VBT (Post 2071515)
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.

Guest190829 07-19-2010 01:51 PM

Quote:

Originally Posted by kh99 (Post 2071520)
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.

kh99 07-19-2010 01:59 PM

Quote:

Originally Posted by Danny.VBT (Post 2071535)
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. :)

NexDog 07-20-2010 02:55 AM

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).

kh99 07-20-2010 10:12 AM

Quote:

Originally Posted by NexDog (Post 2071834)
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?).

Guest190829 07-22-2010 12:24 AM

Yes, please don't mistake my query for insult, I was wondering why I saw this trend pop up recently and now that I know its in the manual, it's not surprising!


All times are GMT. The time now is 05:05 AM.

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.02487 seconds
  • Memory Usage 1,766KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete