• Resolved Luigino

    (@luigino)


    I have this little php I call from jqGrid url that I use inside an admin’s wordpress plugin:

    require_once($_SERVER['DOCUMENT_ROOT'] . '/xDl21my20/wp-load.php');
    remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
    add_action( 'shutdown', function() {
       while ( @ob_end_flush() );
    } );
    
    global $wpdb;
    
    ob_start();
    $sql_select = "SELECT * FRON TABLE ORDER BY ID ASC";
    
    $results = $wpdb->get_results($sql_select, OBJECT);
    
    return json_encode($results);
    ob_get_clean();

    but I see I don’t receive any results and looking in the log I see this error:

    [02-Jan-2022 09:05:32 UTC] PHP Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/..../wp-includes/functions.php on line 5107

    So since I added that remove_action as I read in other issues, it should have bypassed the ob_end_flush issue but it didn’t… Maybe I forgot something or could be that related to PHP version installed PHP Version 7.4.27?… Any direction would be appreciated… cheers!!!

    btw, zlib_compression is on in php.ini

Viewing 5 replies - 1 through 5 (of 5 total)
  • Not sure if you just created as an example

    "SELECT * FRON TABLE ORDER BY ID ASC"

    FRON

    Can you explain what your code is trying to do? Why are you capturing the output buffer?

    Why are you returning before the last statement so never executed.

    Thread Starter Luigino

    (@luigino)

    Hi Alan.
    – that “SELECT” is just a sample select from a certain table that returns some rows…
    – before to add ob_start() and ob_get_clean() it was without ob_start() neither ob_get_clean() but I got still the error….
    – I added ob_start() and ob_get_clean() because I thought that error could be cause by $wpdb->get_results() which runs thanks to wp-load.php inclusion without success anyway…

    Dion

    (@diondesigns)

    Try this (much simpler) code instead:

    require_once($_SERVER['DOCUMENT_ROOT'] . '/xDl21my20/wp-load.php');
    $sql_select = "SELECT * FROM table ORDER BY ID ASC";
    $results = $wpdb->get_results($sql_select, OBJECT);
    
    if (!empty($results)) {
    	echo (string) json_encode($results);
    }

    Yes I suspect the use of return is miss understood here.

    return will exit a function returning data to a calling function

    in this case as a standalone script, return will simply terminate as there is nothing up the stack to pass data to.

    I suspect it is as Dion says, the intent is to output.

    Thread Starter Luigino

    (@luigino)

    Hello Dion!
    Thank you for your answer!
    It looks like the problem was relating on returning result…
    Usually I use “return $variable (or $object)” to return results to sender but in this case it looks like it needs “echo” to return results and in fact I see in Chrome’s response debug the json string.
    Thank you again.
    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ob_end_flush(): failed to send buffer of zlib output compression in ext php file’ is closed to new replies.