Prevent output from a script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Prevent output from a script

Post by jmut »

Hi I have one script that is used for somthing.
But I will use it in a cronjob so I want it to produce no output (dev/null of the script is no opion).

Code: Select all

foreach ($someting as $data) {

include("script_that_produce_output_I_dont_need");

}
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

if you use output functions like echo() or somthing then it is going to produce output, no way of avoiding that. Also, use error_reporting(E_NONE) so no errors are outputted.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

With http://www.php.net/ob_start and http://www.php.net/ob_flush you can prevent (most of) the output... Now cross your fingers and hope that there are no headers being generated...
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

well there are echos and var_dumps and stuff :(
I don't see how there will be no headers generated.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

found a solution.
using curl and don't output any result from it
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

timvw's direction is the general way to go. Using curl can involve a lot of extra overhead that you shouldn't really need.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

feyd wrote:timvw's direction is the general way to go. Using curl can involve a lot of extra overhead that you shouldn't really need.
yes but what about the headers.

"Now cross your fingers and hope that there are no headers being generated..."

I mention there are plenty of echos and stuff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If there are lots of echos, typically there is no extra headers being set for a lot of people. You could always make sure to override the headers after including the file too.
Post Reply