mikemcg
mikemcg

Reputation: 393

What happens behind the scenes when I echo out a variable?

I'm sorry if my wording is going to be off or my question is a little too vague.

Let's say I have a simple script sitting on an Ubuntu box running Apache with mod_php. This is the entirety of my script:

<?php
echo 'Hello, World!';
?>

What happens when I call echo? Does the text get written to a buffer somewhere and then sent to the client when the script ends? I'd like to get a handle on something low level like that.

Upvotes: 2

Views: 139

Answers (3)

Marty McVry
Marty McVry

Reputation: 2856

Usually, the script output (notice my phrasing) gets sent directly to the client during the parsing of the script. When you want to store (read: buffer) the output before sending it, you can use output buffering, like Yazmat already mentioned.

Upvotes: 1

What's in my mind is, when the server is called by a client to view their hosted PHP file, the server will sent an executed PHP script to the client, so it's not a PHP script anymore.

Upvotes: 0

Oussama Jilal
Oussama Jilal

Reputation: 7749

I think you are looking for this : Output Buffering

Upvotes: 0

Related Questions