Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture output from PHP extension when using PHP-FPM

I have a custom C extension loaded in my PHP and inside the extension there's a function does something like this

void a() {
    printf("abc");
}

I can call a() with no problem in CLI mode (command-line) and got the output abc as expected. But when i tried again in our Yii project in PHP-FPM mode,I couldn't get that output.

What I am sure about is:

  • The extension is loaded.
  • The function call is successfully made with no error.
  • PHP output buffering is turned off. I called ob_end_clean() twice before calling a(), the first call return true and the second returned false.

So my question is:

Am I supposed to get output from extensions in PHP-FPM mode?

If so, how can I capture the output, or please shoot me some debugging advice.

like image 646
Lution Avatar asked Feb 08 '18 08:02

Lution


1 Answers

When PHP runs as a webserver module, stdout is redirected to the terminal from which the webserver process was originally started. On production server such a terminal is not active, so any output that you send to stdout will be lost.

try php_printf() function istead of printf() one

probably this article can help you https://devzone.zend.com/317/extension-writing-part-ii-parameters-arrays-and-zvals/

like image 153
bxN5 Avatar answered Oct 11 '22 07:10

bxN5