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
Old 07-12-2010, 10:45 AM Performance Question
Junior Talker

Posts: 1
Name: Jeff
Trades: 0
I have a question about performance. I want to capture a whole page as a variable and echo it back to the browser, but I'm not sure that it's the best idea. It seems to me like I'd only be making one call to the PHP interrupter, instead of over and over with a marked up page. Does anyone have any experience with this that can offer some advice?

Just for illustration:
<?php
$output = "<html><head><title>This is a test</title></head><body>This page is just a test";
$output.= call_some_function();
$output.= do_other_stuff();
$output.= "</body></html>";
echo $output;
?>

As opposed to :
<html>
<head>
<title>This is a test</title>
</head>
<body>
This page is just a test
<?php call_some_function(); ?>
<?php do_other_stuff(); ?>
</body>
</html>
Archer0537 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-12-2010, 10:57 AM Re: Performance Question
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You can just use an output buffer to capture any output and store it in a variable:
PHP Code:
<?php
ob_start
();
?>
<html>
<head>
<title>This is a test</title>
</head>
<body>
This page is just a test
<?php call_some_function(); ?>
<?php do_other_stuff
(); ?>
</body>
</html>
<?php
$output 
ob_get_clean();
echo 
$output;
?>
The performance difference between capturing the output and storing it, rather than outputting it immediately should be negligible.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Performance Question
 

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.32874 seconds with 12 queries