php script and output redirection

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
mhg
Posts: 4
Joined: Tue Nov 22, 2005 2:28 pm

php script and output redirection

Post by mhg »

I've seen something strange today. I tried to develop a php Script/Command. I couldn't get output of the script (via print()) in Cacti, although the script run correctly in the Unix shell. Finally I realized no output was even present just after the script was run in poller.php. The command line was:

/usr/local/bin/php <path>/myscript.php <param1> <param2>

Finally I tried to do something with output redirection:

/usr/local/bin/php <path>/myscript.php <param1> <param2> 2>&1

Unexpectedly I _got_ the output in Cacti and I saw the graph!

This is PHP cli 4.4.0 under Solaris. I really don't know what could be the reason of this behavior. This is for the records. Any comments?
User avatar
bulek
Cacti Pro User
Posts: 854
Joined: Mon May 20, 2002 2:07 am
Location: Poland
Contact:

Post by bulek »

What you just did is redirection of error output to normal output stream. It may happen that your script reports some error which is taken as a normal output of your script.

- Piotr
mhg
Posts: 4
Joined: Tue Nov 22, 2005 2:28 pm

Post by mhg »

bulek wrote:It may happen that your script reports some error which is taken as a normal output of your script.
no, it's not the case, there are no errors. the script just returns designed correct output results - using print(). these results are visible when running at the prompt in terminal window, they're even visible when script is called from another script, but the're not visible in Cacti (until output redirection is applied).
User avatar
bulek
Cacti Pro User
Posts: 854
Joined: Mon May 20, 2002 2:07 am
Location: Poland
Contact:

Post by bulek »

Well... yes, I understand that the script works correctly from command line. The difference is that cacti runs the scripts using crontab... in crontab there is some minimal environment defined - variables, path - and there can be missing something. This is quite common when a script works in shell but does not in Cacti. Try to redirect whole output to some file (inside crontab file) and look at the potential errors.

- Piotr
mhg
Posts: 4
Joined: Tue Nov 22, 2005 2:28 pm

Post by mhg »

bulek wrote:The difference is that cacti runs the scripts using crontab...
actually the scripts are run by php's popen() in poller.php, which in turn runs under crontab indeed. it's not clear what environment is defined for processes run by popen().
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

What version of glibc are you running? I just saw this recently on a development version of GLIBC where stderr would fire the underlying select statement within popen function causing pre-mature return of partial results.

TheWitness

p.s. This would be caused by some warning or the like from your popen call.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
mhg
Posts: 4
Joined: Tue Nov 22, 2005 2:28 pm

Post by mhg »

TheWitness wrote:What version of glibc are you running?
actually it's under Solaris (see the original post).
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests