Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 404731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:20:06+00:00 2026-05-12T17:20:06+00:00

I have a long-running script that seems to occasionally report the following NOTICE-level error:

  • 0

I have a long-running script that seems to occasionally report the following NOTICE-level error:

pg_send_query(): Cannot set connection to blocking mode

It seems to continue to send queries afterward, but it’s unclear if it successfully sends the query that generates the error.

What is this a symptom of?

Edit: There are no entries in the postgres log at the time the error occurred, suggesting this is solely a connection error, not something going wrong on postgres’ side (e.g. probably not the result of postgres crashing and restarting or something)

Edit: As far as I can tell, my INSERT statements are succeeding, one way or another, when this error is triggered.

Edit: Looks like this may have been fixed in June 2013: https://bugs.php.net/bug.php?id=65015

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:20:06+00:00Added an answer on May 12, 2026 at 5:20 pm

    It is a symptom of pg_send_query() not being able to successfully switch the connection back to blocking mode. Looking at the source code in PHPs pgsql.c, you can find:

    /* {{{ proto bool pg_send_query(resource connection, string query)
       Send asynchronous query */
    PHP_FUNCTION(pg_send_query)
    {
    
    <... snipped function setup stuff ...>
    
     if (PQ_SETNONBLOCKING(pgsql, 1)) {
      php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to nonblocking mode");
      RETURN_FALSE;
     }
    
    <... snipped main function execution stuff ...>
    
     if (PQ_SETNONBLOCKING(pgsql, 0)) {
      php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
     }
     RETURN_TRUE;
    }
    

    So the error gets raised at the end of the function, after the main work is done. This fits with your observation that your INSERT statements get executed.

    The whole purpose of the two PQ_SETNONBLOCKING calls is to put the connection in non blocking mode to allow asynchronous execution and putting it back to the default blocking behaviour afterwards. From the documentation of PQsetnonblocking: (PQ_SETNONBLOCKING is just an alias defined for that function):

    Sets the nonblocking status of the
    connection.

    int PQsetnonblocking(PGconn *conn, int arg);
    

    Sets the state of the connection to nonblocking if arg is 1,
    or blocking if arg is 0. Returns 0 if
    OK, -1 if error.

    In the nonblocking state, calls to
    PQsendQuery, PQputline, PQputnbytes,
    and PQendcopy will not block but
    instead return an error if they need
    to be called again.

    Note that PQexec does not honor
    nonblocking mode; if it is called, it
    will act in blocking fashion anyway.

    Looking further at the source of PQsetnonblocking (in PostgeSQLs fe-exec.c), there are two possible reasons why the call could fail:

    /* PQsetnonblocking:
     * sets the PGconn's database connection non-blocking if the arg is TRUE
     * or makes it non-blocking if the arg is FALSE, this will not protect
     * you from PQexec(), you'll only be safe when using the non-blocking API.
     * Needs to be called only on a connected database connection.
     */
    int
    PQsetnonblocking(PGconn *conn, int arg)
    {
     bool  barg;
    
     if (!conn || conn->status == CONNECTION_BAD)
      return -1;
    
     barg = (arg ? TRUE : FALSE);
    
     /* early out if the socket is already in the state requested */
     if (barg == conn->nonblocking)
      return 0;
    
     /*
      * to guarantee constancy for flushing/query/result-polling behavior we
      * need to flush the send queue at this point in order to guarantee proper
      * behavior. this is ok because either they are making a transition _from_
      * or _to_ blocking mode, either way we can block them.
      */
     /* if we are going from blocking to non-blocking flush here */
     if (pqFlush(conn))
      return -1;
    
     conn->nonblocking = barg;
    
     return 0;
    }
    

    So either the connection got lost somehow, or pqFlush did not finish successfully, indicating leftover stuff in the connection output buffer.

    The first case would be harmless, as your script would certainly notice the lost connection for later calls and react to that (or fail more noticeable).

    This leaves the second case, which would mean you have a connection in the non default, non blocking state. I do not know if this could affect later calls that would reuse this connection. If you want to play it safe, you’d close the connection in this case and use a new/other one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long running BASH script that I am running under CYGWIN on
I have a long running redgate script that is applying a bunch of schema
I have a long-running Python script that I run from the command-line. The script
I have a long-running multithreaded program, and I'd like to occasionally like to call
I have a long-running cleanup operation that I need to perform in onDestroy() of
I occasionally have some long running AJAX requests in my Wicket application. When this
I have a long running php script which is basically an infinite loop listening
What I have is NSTask running a long premade shell script and I want
I have a long running program, my_prog that has some output that I want
I have some long-running CLI PHP scripts that run regularly via cron. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.