0

We recently had PHP version upgraded to 5.3.3 on our server (running Wordpress) and since then the mysql_query function started hanging the server, producing the error Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data in Google Chrome.
The connection parameters are correct and error logging is also turned on but nothing appears.
What could be wrong? What should I check?

UPDATE:

The code:

function query( $query ) {
    if ( ! $this->ready )
        return false;

    // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
    if ( function_exists( 'apply_filters' ) )
        $query = apply_filters( 'query', $query );

    $return_val = 0;
    $this->flush();

    // Log how the function was called
    $this->func_call = "\$db->query(\"$query\")";

    // Keep track of the last query for debug..
    $this->last_query = $query;

    if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
        $this->timer_start();

    // use $this->dbh for read ops, and $this->dbhwrite for write ops
    // use $this->dbhglobal for gloal table ops
    unset( $dbh );
    if( defined( 'WP_USE_MULTIPLE_DB' ) && WP_USE_MULTIPLE_DB ) {
        if( $this->blogs != '' && preg_match("/(" . $this->blogs . "|" . $this->users . "|" . $this->usermeta . "|" . $this->site . "|" . $this->sitemeta . "|" . $this->sitecategories . ")/i",$query) ) {
            if( false == isset( $this->dbhglobal ) ) {
                $this->db_connect( $query );
            }
            $dbh =& $this->dbhglobal;
            $this->last_db_used = "global";
        } elseif ( preg_match("/^\\s*(alter table|create|insert|delete|update|replace) /i",$query) ) {
            if( false == isset( $this->dbhwrite ) ) {
                $this->db_connect( $query );
            }
            $dbh =& $this->dbhwrite;
            $this->last_db_used = "write";
        } else {
            $dbh =& $this->dbh;
            $this->last_db_used = "read";
        }
    } else {
        $dbh =& $this->dbh;
        $this->last_db_used = "other/read";
    }

    $this->result = @mysql_query( $query, $dbh );
    $this->num_queries++;

    if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
        $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );

    // If there is an error then take note of it..
    if ( $this->last_error = mysql_error( $dbh ) ) {
        $this->print_error();
        return false;
    }

    if ( preg_match( "/^\\s*(insert|delete|update|replace|alter) /i", $query ) ) {
        $this->rows_affected = mysql_affected_rows( $dbh );
        // Take note of the insert_id
        if ( preg_match( "/^\\s*(insert|replace) /i", $query ) ) {
            $this->insert_id = mysql_insert_id($dbh);
        }
        // Return number of rows affected
        $return_val = $this->rows_affected;
    } else {
        $i = 0;
        while ( $i < @mysql_num_fields( $this->result ) ) {
            $this->col_info[$i] = @mysql_fetch_field( $this->result );
            $i++;
        }
        $num_rows = 0;
        while ( $row = @mysql_fetch_object( $this->result ) ) {
            $this->last_result[$num_rows] = $row;
            $num_rows++;
        }

        @mysql_free_result( $this->result );

        // Log number of rows the query returned
        // and return number of rows selected
        $this->num_rows = $num_rows;
        $return_val     = $num_rows;
    }

    return $return_val;
}

The line that causes the error is $this->result = @mysql_query( $query, $dbh );
I am currently investigating the value of $dbh.
mysql_query without parameters produced a warning, so at least it is working.

Priednis
  • 754
  • 1
  • 8
  • 19
  • Question is unanswerable without the php code that performs the `mysql_query`, voting to close. – Johan Sep 23 '11 at 11:57
  • When calling the mysql_query function with empty parameters ('','') I got a correct warning, which means that the function as such is working, but as soon as the second (connection) argument is passed, the ERR_EMPTY_RESPONSE error happens. The connection parameter gets successfully created in the class constructor. But obviously there is some problem with the connection. – Priednis Sep 23 '11 at 14:02
  • I would echo the query you are running `$query` and see if it's valid SQL. Also this dynamic query building in php sound like a security nightmare: http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain – Johan Sep 23 '11 at 14:08
  • I tried using empty query "" or something very simple like SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'. In both these cases the empty response error happens. – Priednis Sep 23 '11 at 14:18
  • Can this be somehow related to PHP or MySQL configuration or the fact that PHP runs as CGI on *nix? – Priednis Sep 23 '11 at 14:59
  • Some googling revealed: If your hosting is behind NGINX or you have a custom security module in your wordpress set to emit a 444 http header, this would cause the error you're getting. You might wanna search your code for header() calls or ask your host what is sending a 444 header. – Johan Sep 23 '11 at 15:09

0 Answers0