views:

123

answers:

2

Hi Folks,

i have got a php-script foo.php

#!/usr/bin/php -c /etc/php5/cli/php.ini -q
<?php
  echo 'hello'; // & do some stuff
?>

I call this script not wrapped by a sh-script but using it directly in a cron job. To get rid of it's output i normally would just create a sh-file which calls

/usr/bin/php -c /etc/php5/cli/php.ini -q foo.php > /dev/null 2 > /dev/null 

now i'd like to do this in the interpreter-declaration of the php file it self... so i am looking for the syntax for:

#!/usr/bin/php -args [file's content] > /redirect 2 > /redirect

i have kind of a hard time googleing for it... so if anybody could point me into the right direction i would really appreciate it!

Thx in advance

Corelgott

A: 

The shebang statement was never intended to control the output of the script, it's more of a use this program to execute what's underneath here type deal, as such there's no option for what you want.

Unless the interpreter itself has an output argument (which the php cli doesn't), you will need to keep the > /dev/null statement in the crontab line.

You could also modify your scripts to have a global boolean $output, surrounding all print statements with if statements and include that at the top of the file.

Cetra
A: 

Like, @Victor Stanciu said, you redirect the output directly in the cron job command, but the only other way I can think of is:

php -r "ob_start(); include 'my_script'; ob_end_clean();"

I think you could close stdout with fclose(STDOUT), but apparently the constants STDIN, STDOUT and STDERR no longer exist.

Artefacto