Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to make a simple control panel for my webserver running nginx with php-fpm.

I've managed to catch result of service php5-fpm restart and service nginx reload, but the output from nginx -t apparently doesn't work the same way?

I've tried with $out = shell_exec('nginx -t');, like I use for the other 2 examples above. But when I run the script, it just prints out the result and the variable $out is null.

I've also tried with both shell() using the output argument and popen() combined with fread(), but that's the same outcome.

What I want to achieve is updating a field in my mysql database with the result of nginx -t.

Is there anyway to do this?

share|improve this question

closed as off-topic by Luis Alvarado Jul 25 at 1:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Luis Alvarado
If this question can be reworded to fit the rules in the help center, please edit the question.

    
What do you get when you enter nginx -t from a terminal? Also, please upload the full scope of your PHP code. –  Lucio Feb 11 at 19:25
1  
This is solely programming question and belongs to stack overflow. nginx -t probably prints output to stderr. –  Olli Feb 11 at 19:28

1 Answer 1

up vote 2 down vote accepted

This is more a programming than ubuntu question so it should probably be in stack overflow.

However your problem is probably errors not being caught because you are asking for STDOUT and errors are being output to STDERR.

There are two possible solutions.

The first is to use a php function to capture STDERR. I don't know enough php to answer that.

The second is to direct STDERR into STDOUT. Run

nginx -t 2>&1

This tells the shell to move everything written to STDERR to STDOUT instead.

For more info on file streams and stderr in particular: http://en.wikipedia.org/wiki/Standard_streams#Standard_error_.28stderr.29

share|improve this answer
    
Thanks, that did it! Sorry if I've used a wrong forum, I thought it was as much an Ubuntu-matter. And as it turned out, it was the command which need to be changed ;-) –  majbom Feb 12 at 19:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.