5

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.

Hammer
  • 1,514
  • 2
  • 14
  • 22
  • When you say 'What I am sure about is:- The extension is loaded.' do you mean you have echoed phpinfo on one of the web pages under your yii project and found your extension. – Kamal Soni Feb 11 '18 at 00:11
  • @KamalSoni Yes. Actually there are several functions in the extension. They all worked properly in the Yii project except for the issue that i can't get the output made by `printf` – Hammer Feb 11 '18 at 02:25
  • Ok Great @Lution I think you can debug by doing couple of things and it might help you. 1) Firstly I think your printf function signature does not look right. Should it just have one parameter or more. May be try print instead. 2) Create void b() {printf("abc");} and see if you get anything calling b instead of a. Also after each changes it is worth restarting php-fpm. – Kamal Soni Feb 11 '18 at 03:19

1 Answers1

5

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/

bxN5
  • 1,430
  • 2
  • 16
  • 27