PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Embedding php include within function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Embedding php include within function

    Hi,

    First of all, this is a great search engine! I'm impressed with the speed, quality of results, easy configurability, and the low cost of premium packages!

    I'm having an issue with including search results, the problem code is as follows:

    Code:
    <?php function print_content() { ?>
    
    	<div id="content_total">
    	
    		<?php virtual("search.php"); ?>	
    	
    	</div>
    
    <?php } ?>
    What ends up happening is that my apache 2.2 server spits out a 200+MB error log file, and while my browser is waiting on the results - but the results never come, and I have to restart apache before I can regain control over my system.

    Note that the following works perfectly, and is the method I was using prior to switching to controlling output via functions:


    Code:
    	<div id="content_total">
    	
    		<?php virtual("search.php"); ?>	
    	
    	</div>
    Any idea on what's wrong here? I want the search results to be embedded in a dynamically generated results page. Basically index.php calls an include on content.php, then runs functions print_headers() and print_content() so that header and content adds are written in the correct part of the output html code.

  • #2
    The search script was certainly not designed to be embedded within a function like that. This is not recommended use. We don't quite see why you would need to do this either - you should be able to specify where you want the search content to appear by placement of the "virtual" function call.

    The "search.php" script itself contains functions (which would make little sense when you have it embedded within your function - causing there to be functions declared within the scope of another function), and the main code is expected to be executed immediately (and once per instance). This practice of embedding an external script within a function should really only be attempted with very simple scripts (with no subfunctions etc). With larger, more complex scripts, such as Zoom's, it is almost never a good idea.

    Is there a particular reason why you are trying to functionalize this?
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      Ah that makes sense - I didn't think of it that way, and didn't take the internals of search.php into consideration.

      I was trying the method because it's the way my site is designed.

      index.php includes the content file and calls print_headers() within the head scope, then calls print_content() within the content div scope.

      hmm I'll have a think about this and see if there's another way of doing things.

      Comment

      Working...
      X